题目描述
Niuniu likes mathematics. He also likes drawing pictures. One day, he was trying to draw a regular polygon with n vertices. He connected every pair of the vertices by a straight line as well. He counted the number of regions inside the polygon after he completed his picture. He was wondering how to calculate the number of regions without the picture. Can you calculate the number of regions modulo 1000000007? It is guaranteed that n is odd.
输入描述:
The only line contains one odd number n(3 ≤ n ≤ 1000000000), which is the number of vertices.
输出描述:
Print a single line with one number, which is the answer modulo 1000000007.
示例1
输入
3
输出
1
示例2
输入
5
输出
11
备注:
The following picture shows the picture which is drawn by Niuniu when n=5. Note that no three diagonals share a point when n is odd.
题解
*为符合欧拉公式要求,此多边形指圆的内接多边形
1.圆内共有C(n,2)条直线:任意两点构成一条直线
2.圆内共有C(n,4)个交点:每四个点可构成唯一交点
3.欧拉示性数公式:V-E+F=2
V(Vertical):顶点的数量;E(Edges):边的数量;F(Faces):区域数量
点:所以题中点的数量为V'=n+C(n,4)
边:交点数*2+直线数,将圆上连接顶点的弦看作边。所以E'=C(n,2)+2*C(n,4)+n
总区域数:F'=C(n,2)+2*C(n,4)+n-[n+C(n,4)]+2=C(n,2)+C(n,4)+2
所求多边形内区域和F''=F'-1(圆外区域)-n(弦与边的区域和)
答案
#include<iostream>
const int mod=1e9+7;
typedef long long ll;
using namespace std;
ll quick(ll a,ll b)
{
ll ans=1;
a%=mod;
while(b){
if(b&1)//(b%2==1)
{
ans=ans*a%mod;
}
a=(a*a)%mod;
b>>=1;// b/=2
}
return ans;
}//快速幂
ll C(ll x,ll y)
{
ll ans=1,i;
for(i=x;i>=x-y+1;i--){
ans=ans*i%mod;
}
for(i=1;i<=y;i++){
ans=ans*quick(i,mod-2)%mod;
}
return ans;
}
int main()
{
int n;
cin>>n;
cout<<(C(n,2)+C(n,4)-n+1+mod)%mod;
return 0;
}