D. (C(n,m)和杨辉三角的模)

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

扫描二维码关注公众号,回复: 2743263 查看本文章
3

Output

12

Input

5

Output

180

Input

200000

Output

82096552

题目连接:http://codeforces.com/gym/100187/problem/D

#include<iostream>
#include<string>
#include<cstdio>
#define MAXN 200010
#define mod 1000000009
using namespace std;
long long dp[MAXN];
long long s[MAXN];
long long pow_quick(long long a,long long p)  //用费马小定理求a的模mod的乘法逆元
{                                             //但这里p代入的是mod-2
	long long ans=1;
	while(p)
	{
		if(p&1)
        ans=ans*a%mod;
		p>>=1;
		a=a*a%mod;
	}
	return ans;
}
long long C(long long n,long long m)
{
    long long ans=dp[n]%mod*(pow_quick(dp[m],mod-2)%mod*pow_quick(dp[n-m],mod-2)%mod)%mod;
    ans%=mod;
    return ans;
}
int main()
{
    long long n;
    long long i;
    scanf("%lld",&n);
    s[0]=1;
    dp[0]=1;
    for(i=1;i<=n;i++)
    {
        dp[i]=dp[i-1]*(i%mod);
        dp[i]%=mod;
        s[i]=(s[i-1]*(2%mod))%mod;              //才发现杨辉三角下一层的和是上一层的2倍。
                                                //杨辉三角的取模
    }
    long long sum=0;
	for(i=1;i<n;i++)
    {
         sum+=C(n,i)*(s[n-i]-1)%mod;               //C(n,m)的总和是满足杨辉三角的
         sum%=mod;
    }
	printf("%lld\n",sum);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xigongdali/article/details/81627870