SGU 481 Hero of Our Time java大数+规律

题目链接:点击打开链接


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

public class Solution {
	
	public void work() {
		int n;
		while (cin.hasNext()) {
			n = cin.nextInt();
			BigInteger tmp = BigInteger.ONE;
			for(int i = 3; i < n; i ++) {
				tmp = tmp.multiply(BigInteger.valueOf(i));
			}
			BigInteger ans = tmp;
			for(int i = n-1; i >= 3; i --) {
				tmp = tmp.multiply(BigInteger.valueOf(n)).divide(BigInteger.valueOf(n-i));
				ans = ans.add(tmp);
			}
			System.out.println(ans);
		}
	}

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

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

	public Scanner cin;
}


你可能感兴趣的:(SGU 481 Hero of Our Time java大数+规律)