ACM-ICPC 2017 Asia Urumqi D. Fence Building

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值