首页 > 代码库 > HDU 4927 Series 1 java大数

HDU 4927 Series 1 java大数

java mle前会wa 或者 t 这种事我会乱说?


import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    BigInteger[] a = new BigInteger[3007];

    public void work() {
        int T;
        T = cin.nextInt();
        while (T-- > 0) {
            int n;
            n = cin.nextInt();
            for (int i = 0; i < n; ++i)
                a[i] = cin.nextBigInteger();
            
            int j = n - 1;
            BigInteger C = BigInteger.ONE, sum = BigInteger.ZERO;
            for (int i = 0; i < n; ++i) {
                if (i % 2 == 0) {
                    BigInteger d1 = C.multiply(a[j]);
                    sum = sum.add(d1);
                } else {
                    BigInteger d2 = C.multiply(a[j]);
                    sum = sum.subtract(d2);
                }
                C = C.multiply(BigInteger.valueOf(n - 1 - i)).divide(BigInteger.valueOf(i + 1));
                --j;
            }
            System.out.println(sum);
        }
    }

    Main() {
        cin = new Scanner(System.in);
    }

    public static void main(String[] args) {
        Main e = new Main();
        e.work();
    }

    public Scanner cin;
}