Package es.felixcoto.tuenti

Source Code of es.felixcoto.tuenti.Main

package es.felixcoto.tuenti;

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {
    try {
      Scanner sc=new Scanner(System.in);
      int iNumberOfCases=sc.nextInt();
      int iCasesExecuted=0;
      while (iCasesExecuted<iNumberOfCases){
        iCasesExecuted++;
        long lInput=sc.nextLong();
       
        // The result is obtained using the following formula
        // 1+((n(n+1))/2)
        BigInteger objResult=BigInteger.valueOf(lInput+1);
        objResult=objResult.multiply(BigInteger.valueOf(lInput));
        objResult=objResult.shiftRight(1);// equivalent to divide by 2
        objResult=objResult.add(BigInteger.ONE);
           
        System.out.println(String.format("Case #%s: %s", iCasesExecuted,objResult));
      }
     
     
     
    } catch (Exception e) {
      e.printStackTrace();
    }
   
   
   

  }

}
TOP

Related Classes of es.felixcoto.tuenti.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.