Farmer John owns a farm. He first builds a circle fence. Then, he will choose n points and build some straight fences connecting them. Next, he will feed a cow in each region so that cows cannot play with each other without breaking the fences. In order to feed more cows, he also wants to have as many regions as possible. However, he is busy building fences now, so he needs your help to determine what is the maximum number of cows he can feed if he chooses these n points properly.
Input
The first line contains an integer 1 \le T \le 1000001≤T≤100000, the number of test cases. For each test case, there is one line that contains an integer n. It is guaranteed that 1 \le T \le 10^51≤T≤105 and 1 \le n \le 10^{18}1≤n≤1018.
Output
For each test case, you should output a line ”Case #ii: ans” where ii is the test caseS number, starting from 11and ans is the remainder of the maximum number of cows farmer John can feed when divided by 10^9 + 7109+7.
样例输入
3 1 3 5
样例输出
Case #1: 1 Case #2: 4 Case #3: 16
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
BigInteger modd=new BigInteger("1000000007");
int t;
t=sc.nextInt();
StringBuilder str = new StringBuilder();
for(int i=1;i<=t;i++) {
BigInteger num;
num=sc.nextBigInteger();
BigInteger sum=new BigInteger("1");
sum=sum.multiply(num);
sum=sum.multiply((num.subtract(BigInteger.valueOf(1))));
//System.out.println(sum);
sum=sum.divide(BigInteger.valueOf(2));
//System.out.println(sum);
BigInteger sum2=new BigInteger("1");
for(int j=0;j<4;j++) {
sum2=sum2.multiply((num.subtract(BigInteger.valueOf(j))));
}
sum2=sum2.divide(BigInteger.valueOf(24));
//System.out.println(sum2);
str=str.append("Case #"+i+": "+(sum.add(sum2).add(BigInteger.valueOf(1))).mod(modd)+"\n");
}
System.out.println(str);
}
}
欢迎大家加入 早起学习群,一起学习一起进步!(群号:642179511)