链接:https://www.nowcoder.com/acm/contest/146/G
来源:牛客网
题目描述
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.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
/*
真是太SB了,明明做过
当时看着就是做过的,推了一会公式后发现,忘了怎么推的了,所以直接找题解(uva 10213)
发现答案不一样,当时就蒙蔽了,觉得这道题是晃我们这些做过的,所以就放弃了,特别SB,不知道来看看那个还有个
圆啊,简直崩溃
还是要学习方法,毕竟考试的时候是没有这么好的事的
*/
ll pow_mod(ll base,int n){
ll ans=1;
while(n){
if(n&1)ans=ans*base%mod;
base=base*base%mod;
n>>=1;
}
return ans%mod;
}
ll inv2,inv6,inv4;
void init(){
inv2=pow_mod(2,mod-2);
inv4=pow_mod(4,mod-2);
inv6=pow_mod(6,mod-2);
}
//坑点:一乘 一mod
ll getv(ll n){
ll tmp1=(n-2)*(n-2)%mod*(n-3)%mod*inv2%mod;
ll tmp2=(n-3)*(n-2)%mod*(2*n-5)%mod*inv6%mod;
ll tmp=(tmp1-tmp2+mod)%mod;
tmp=tmp*n%mod*inv4%mod;
return (tmp+n)%mod;
}
ll gete(ll n){
ll tmp1=(n-2)*(n-2)%mod*(n-3)%mod*inv2%mod;
ll tmp2=(n-3)*(n-2)%mod*(2*n-5)%mod*inv6%mod;
ll tmp=(tmp1+mod-tmp2+n-3+mod)%mod;
tmp=tmp*n%mod*inv2%mod;
return (tmp+n)%mod;
}
int main()
{
init();
ll n;
while(scanf("%lld",&n)==1){
ll V=getv(n),E=gete(n);
printf("%lld\n",(E+1-V+mod)%mod);
}
return 0;
}