UVA 10213(p336)----How Many Pieces of Land

import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
    static PrintWriter out = new PrintWriter(new  BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main(String args[]) throws IOException
    {
        Scanner cin=new Scanner(System.in);
        int kase = cin.nextInt();
        for(int c = 1; c <= kase; ++c)
        {
            BigInteger ans = BigInteger.valueOf(1);
            String s = cin.next();
            BigInteger n = new BigInteger(s);
            BigInteger temp = new BigInteger(s);
            temp = temp.multiply(temp.subtract(new BigInteger("1")));
            temp = temp.divide(new BigInteger("2"));
            ans = ans.add(temp);
            temp = temp.multiply(n.subtract(new BigInteger("2")));
            temp = temp.multiply(n.subtract(new BigInteger("3")));
            temp = temp.divide(new BigInteger("12"));
            ans = ans.add(temp);
            System.out.println(ans);
        }
    }
}

你可能感兴趣的:(UVA 10213(p336)----How Many Pieces of Land)