牛客网

3 篇文章 0 订阅

链接: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.

 

#include <iostream>
#define ll long long
using namespace std;
const ll mod=1000000007;
//多边形所有不相邻的角连线之后的区域个数,
ll multi(ll a,ll b)
{
      ll ans=0;
      while(b)
      {
            if(b&1) ans=(ans+a)%mod;
            a=(a+a)%mod;
            b>>=1;
      }
      return ans;
}
ll powq(ll a,ll b)
{
      ll ans=1;
      while(b)
      {
            if(b&1) ans=multi(ans,a)%mod;
            
            a=multi(a,a)%mod;
            b>>=1;
      }
      return ans;
}
int main()
{
    int n;
   while(cin>>n){
         int niyuan=41666667;
         ll x=((24-42*n+23*powq(n,2)-6*powq(n,3)+powq(n,4))*niyuan)%mod;
         cout<<(x+mod)%mod<<endl;
   }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值