首页 > 编程语言 > 详细

HDU 4927 Series 1 java大数

时间:2014-08-07 23:04:25      阅读:369      评论:0      收藏:0      [点我收藏+]

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;
}



HDU 4927 Series 1 java大数,布布扣,bubuko.com

HDU 4927 Series 1 java大数

原文:http://blog.csdn.net/qq574857122/article/details/38427225

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!