当前位置: 代码迷 >> 综合 >> HDU 4927 Series (JAVA大数+组合规律)
  详细解决方案

HDU 4927 Series (JAVA大数+组合规律)

热度:29   发布时间:2023-11-15 15:27:26.0

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4927


import java.util.Scanner;import java.math.BigInteger;public class Main {public static void main(String[] args) { Scanner cin =  new Scanner(System.in); BigInteger[] a;a = new BigInteger[3005];int cas, n;cas    = cin.nextInt();;for (int k = 0; k < cas; k++) {n = cin.nextInt();for (int i = 0; i < n; i++)a[i] = cin.nextBigInteger();BigInteger ans = BigInteger.valueOf(0);BigInteger c = BigInteger.valueOf(1);;for (int i = 0; i < n; i++) {BigInteger tmp = c.multiply(a[n-i-1]);if (i%2 == 0)ans = ans.add(tmp);elseans = ans.subtract(tmp);tmp = c.multiply(BigInteger.valueOf(n-i-1));c = tmp.divide(BigInteger.valueOf(i+1));}System.out.println(ans);}} }

 

  相关解决方案