牛客网多校第八场 G Counting regions

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zy704599894/article/details/81667573

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

扫描二维码关注公众号,回复: 3411643 查看本文章
#include<stdio.h>
#include<algorithm>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll qsm(ll a, ll b)
{
	ll ans = 1;
	while (b)
	{
		if (b % 2 == 1) ans = ans*a%mod;
		a = a*a%mod, b /= 2;
	}
	return ans;
}
int main()
{
	ll n, ans;
	scanf("%lld", &n);
	ans = ((24 - 42 * n + 23 * qsm(n, 2) - 6 * qsm(n, 3) + qsm(n, 4))*qsm(24, mod - 2)) % mod;
	ans = (ans + mod)%mod;
	printf("%lld\n", ans);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/zy704599894/article/details/81667573
今日推荐