Gym - 100187D [逆元]

10 篇文章 0 订阅
4 篇文章 0 订阅

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.

Example
Input
2
Output
2
Input
3
Output
12
Input
5
Output
180
Input
200000
Output
82096552
link

题解

对5这个样例做个解释如下
这里写图片描述

不难的到答案

ans=i=1n1Cin(2ni1)

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#define MAX_N 200005
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define MOD 1000000009
using namespace std;
typedef long long LL;

LL fac[MAX_N];//阶乘表 

void init(){
    fac[1]=1;
    for(int i=2;i<MAX_N;i++)
        fac[i]=fac[i-1]*i%MOD;
}
//扩展欧几里得 
LL exGcd(LL a,LL b,LL &x,LL &y){
    if(b==0){
        x=1,y=0;
        return a;
    }
    LL q=exGcd(b,a%b,y,x);
    y-=a/b*x;
    return q;
}
//逆元 
LL mod_inverse(LL a){
    LL x,y;
    exGcd(a,MOD,x,y);
    return (MOD+x)%MOD;
}

LL mod_pow(LL a,int n){
    LL res=1;
    while(n){
        if(n&1) res=res*a%MOD;
        a=a*a%MOD;
        n>>=1;
    }
    return res;
}

int main()
{
    init();
    int n;
    scanf("%d",&n);
    LL ans=0;
    for(int i=1;i<n;i++){
        ans+=fac[n]*mod_inverse(fac[n-i])%MOD*mod_inverse(fac[i])%MOD*(mod_pow(2,n-i)-1)%MOD;
        ans%=MOD;
    }
    printf("%lld\n",ans);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值