codeforces-gym-100187-D【组合数】【逆元】

题目链接:点击打开链接

D. Holidays
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Everyone knows that the battle of Endor is just a myth fabled by George Lucas for promotion of his movie. Actually, no battle of Endor has happened and the First Galactic Empire prospers to this day.

There are creatures of n races living in the First Galactic Empire. In order to demonstrate their freedom, equality and brotherhood the Emperor commanded to introduce the holidays. During each of these holidays creatures of one non-empty subset of races should give gifts to creatures of another non-empty subset of races, not intersecting the first one.

The Emperor's stuff is not very strong in maths so you should calculate how many such holidays can be introduced. Two holidays are considered different if they differ in the subset of races which give gifts or in the subset of races which receive gifts.

Input

The input contains the only integer n (1 ≤ n ≤ 200000) — the number of races living in the First Galactic Empire.

Output

Find the number of holidays the Emperor commanded to introduce. This number can be very large, so output the reminder of division of this number by 109 + 9.

Examples
input
2
output
2
input
3
output
12
input
5
output
180
input
200000
output
82096552


大意:每一个集合都可以是一个种族,每个假日选定一些种族作为一个集合,这个集合应该给任何与他没有相交的种族礼物,有n个种族,问你最后要给多少假日?

在每一个假日中,一个非空的种族的成员都应该给另一个非空的种族的成员提供礼物。

两个假日中,如果集合分别给不同的种族礼物,那么这两个假日被认为是不同的 。 


题解:首先选出 i 个种族作为一个集合(送礼物的),然后给剩下 n-i 个种族送礼物。即:


#include
#include
#include
#define LL long long
using namespace std;
const LL MOD=1e9+9;
LL n;
LL fac[200010];
LL qpow(LL a,LL b)
{
	LL ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return ans;
}
LL C(LL x,LL y)
{
	return fac[x]*qpow(fac[x-y],MOD-2)%MOD*qpow(fac[y],MOD-2)%MOD;
}
int main()
{
	fac[0]=1;
	for(int i=1;i<200001;i++)
		fac[i]=fac[i-1]*i%MOD;
	while(~scanf("%lld",&n))
	{
		LL ans=0;
		for(int i=1;i


你可能感兴趣的:(逆元,Codeforces)