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<cstdio>
#include<algorithm>
#include<cstring>
#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<n;i++)
		{
			ans=(ans+C(n,i)*(qpow(2,n-i)-1)%MOD)%MOD;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值