题目描述
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个点可以把圆分为几个区域
分析:根据欧拉定理可知:边-点+2=区域个数
点:v=n+C(n,4),四个点有一个交点
边:e=n(圆弧上的)+C(n,2) +2*C(n,4),两个点连成一条线,内部的一个交点分两条线为四条线
求圆内部有多少区域,所以算出来的区域个数再减去圆外部的一个区域
所以为C(n,4)+C(n,2)+1
代码如下:
#include <bits/stdc++.h>
#define pre(i,x,n) for(int i=x;i<=n;i++)
#define ll long long
using namespace std;
ll fac[100010],p=1000000007;
void intt()
{
fac[0]=fac[1]=1;
pre(i,2,p){fac[i]=fac[i-1]*i%p;}
}
ll qpow(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=ans*x%p;
x=x*x%p;
y>>=1;
}
return ans;
}
ll C(ll a,ll b)
{
if(b>a)
return 0;
ll ans=1;
pre(i,1,b)
{
ll n=(a-b+i)%p;
ll m=i%p;
ans=ans*(qpow(m,p-2)*n%p)%p;
}
return ans;
}
ll lucas(ll a,ll b)
{
if(b==0)
return 1;
return C(a%p,b%p)*lucas(a/p,b/p)%p;
}
int main()
{
ll t,n;
int cas=1;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
printf("Case #%d: %lld\n",cas++,(lucas(n,2)+lucas(n,4)+1)%p);
}
return 0;
}