5215: Fence Building
时间限制: 1 Sec 内存限制: 128 MB
提交: 404 解决: 75
[提交] [状态] [讨论版] [命题人:admin]
题目描述
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.
输入
The first line contains an integer 1 ≤ 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 ≤ T ≤ 105 and 1 ≤ n ≤ 1018 .
输出
For each test case, you should output a line ”Case #i: ans” where i is the test case number, starting from 1 and ans is the remainder of the maximum number of cows farmer John can feed when divided by 109 + 7.
样例输入
3 1 3 5
样例输出
Case #1: 1 Case #2: 4 Case #3: 16
简化的题意就是求n个点在圆上,然后相互连接出来,然后得到多个分割区域,求为n时分割区域为多少
最终代码如下
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e9+7;
void ex_gcd(ll a,ll b,ll &x,ll &y,ll &d)
{
if(!b){d=a;x=1;y=0;}
else
{
ex_gcd(b,a%b,y,x,d);
y-=x*(a/b);
}
}
ll inv(ll a,ll p)
{
ll d,x,y;
ex_gcd(a,p,x,y,d);
return d==1?(x%p+p)%p:-1;
}
int main(){
ll n;
int t;
scanf("%d",&t);
//ios::sync_with_stdio(0);cin.tie(0);
int tot=1;
while(t--){
ll ans1=inv(2,N);//cout<<ans1<<endl;
ll ans2=inv(24,N);
scanf("%lld",&n);
ll n1=n%N;
ll n2=(n-1)%N;
ll n3=(n-2)%N;
ll n4=(n-3)%N;
ll ans=n1*n2%N*ans1%N+n1*n2%N*n3%N*n4%N*ans2%N;
printf("Case #%d: %lld\n",tot++,(ans+1)%N);
}
return 0;
}
这题用cin,cout会超时注意一下!!以后还是用老c的输入吧>==<