Pigeon days to put pigeon sequence --- cow-off network

A learned permutations of formula

 

 

 

 

 

#include <iostream>
#include <string.h>
#include <stdio.h>
 
using namespace std;
typedef long long LL;
const LL p = 1e9 + 7;
LL n,m;
LL quick_mod(LL a, LL b)
{
    LL ans = 1;
    a %= p;
    while(b)
    {
        if(b & 1)
        {
            ans = ans * a % p;
            b--;
        }
        b >>= 1;
        a = a * a % p;
    }
    return ans;
}
  
LL C(LL n, LL m)
{
    if(m > n) return 0;
    LL ans = 1;
    for(int i=1; i<=m; i++)
    {
        LL a = (n + i - m) % p;
        LL b = i % p;
        ans = ans * (a * quick_mod(b, p-2) % p) % p;
    }
    return ans;
}
  
LL Lucas(LL n, LL m)
{
    if(m == 0) return 1;
    return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
  
int main(){
   
    int n,m,k;
    cin>>n>>k;
    if(k==0){
        cout<<1<<endl;
        return 0;
    }
    LL ans=0;
    if(k%2 == 0){
    	m = k/2;
		ans = C(n-k+m-1,m-1);
	} 
	else{
		m = (k-1)/2;
		ans = C(n-k+m,m);
	}
    cout<<ans<<endl;
    
     
    return 0;
}

  

Guess you like

Origin www.cnblogs.com/lesning/p/11725794.html