2022牛客五一集训派对day1-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.

 题解

*为符合欧拉公式要求,此多边形指圆的内接多边形

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

易江南20

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

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

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

打赏作者

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

抵扣说明:

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

余额充值