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.

 

输入

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

2020/3/16

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值