P3414 SAC#1 - 组合数 题解

题目背景

本题由世界上最蒟蒻最辣鸡最撒比的SOL提供。

寂月城网站是完美信息教室的官网。地址:http://191.101.11.174/mgzd 。

题目描述

辣鸡蒟蒻SOL是一个傻逼,他居然觉得数很萌!

今天他萌上了组合数。现在他很想知道sigma(C(n,i))是多少;其中C是组合数(即C(n,i)表示n个物品无顺序选取i个的方案数),i取从0到n所有偶数。

由于答案可能很大,请输出答案对6662333的余数。

输入输出格式

输入格式:

输入仅包含一个整数n。

输出格式:

输出一个整数,即为答案。

输入输出样例

输入样例#1: 复制

3

输出样例#1: 复制

4

说明

对于20%的数据,n <= 20;

对于50%的数据,n <= 1000;

对于100%的数据,n <= 1 000 000 000 000 000 000 (10^18)

题解

组合数简单性质

1、

2、

3、

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M 6662333
ll faction(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%M;
			b>>=1;
		a=(a*a)%M;
	}
	return ans;
}
int main()
{
	ll n;
	ios;
	cin>>n;
	cout<<faction(2,n-1)<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/SuBaiACCa/article/details/87990586