hdu 4927 Series 1

二项式系数展开,系数可以递推得到。注意正负号。

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


public class Main {
	
	public static void main(String[] args) {
		
		Scanner cin = new Scanner(System.in);
		int t = cin.nextInt();
		while(t > 0){
			t--;
			int n = cin.nextInt();
			int flag;//正负标记
			if(n%2 == 1) flag = 1;
			else flag = -1;
			n--;
			int num;
			BigInteger a = new BigInteger("1");
			BigInteger ans = new BigInteger("0");
			for(int i = 0;i <= n;i++){
				num = cin.nextInt();
				ans = ans.add(a.multiply(BigInteger.valueOf(flag)).multiply(BigInteger.valueOf(num)));
				flag=flag*-1;
				a=a.multiply(BigInteger.valueOf(n-i)).divide(BigInteger.valueOf(i+1));
			}
			System.out.println(ans);
		}
	}

}


你可能感兴趣的:(hdu 4927 Series 1)