牛客挑战赛33

牛客挑战赛33

组合数取模,插板。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,k;
ll pow(ll a, ll b, ll m)
{
    ll ans = 1;
    a %= m;
    while(b)
    {
        if(b & 1)ans = (ans % m) * (a % m) % m;
        b /= 2;
        a = (a % m) * (a % m) % m;
    }
    ans %= m;
    return ans;
}
ll inv(ll x, ll p)//x关于p的逆元,p为素数
{
    return pow(x, p - 2, p);
}
ll C(ll n, ll m, ll p)//组合数C(n, m) % p
{
    if(m > n)return 0;
    ll up = 1, down = 1;//分子分母;
    for(int i = n - m + 1; i <= n; i++)up = up * i % p;
    for(int i = 1; i <= m; i++)down = down * i % p;
    return up * inv(down, p) % p;
}
ll Lucas(ll n, ll m, ll p)
{
    if(m == 0)return 1;
    return C(n % p, m % p, p) * Lucas(n / p, m / p, p) % p;
}
int main(){
    ll p=1e9+7;
    cin>>n>>k;
    if(n==0){
       cout<<1<<endl; 
       return 0;
    }
    if(k%2==0)n--,k--; 
    printf("%d\n",C(n-(k-1)/2-1,(k-1)/2,p)); 
} 

 

posted @ 2019-10-18 20:09  wilxx  阅读(192)  评论(0编辑  收藏  举报