牛客网暑期ACM多校训练营(第八场)G(Counting regions)


题目描述

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.

题意:题意:给你一个正n边形,将n个顶点两两连边,问内部有多少个区域。n是奇数。

官方思路:

欧拉公式:F=E-V+2(F面,E交点,V线段数)

内部交点个数:C(n,4)
一条线段会被一个交点分成两段,所以x条直线的交点会多分出来x条线段,利用V 可以算出E。

故公式:(n−1)(n−2)(n2−3n+12)/24

证明推荐:https://blog.csdn.net/mjwu1940/article/details/79861021

代码:

 long long qpow(long long a,long long b){
    long long ans=1;
    long long k=a;
    while(b){
        if(b&1)ans=ans*k%mo;
        k=k*k%mo;
        b>>=1;
    }
    return ans;
}
int main(){
    long long n;
    while (scanf("%lld",&n)!=EOF){
        long long ans=(((n-1)*(n-2)%mo)*((n*n-3*n+12)%mo)%mo*qpow(24,mo-2)%mo+mo)%mo;
        cout<<ans<<endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值