#include <iostream> #include <algorithm> #include <cstdio> using namespace std; #define ll long long #define mod 110119 ll factorial[110200]; ll mod_pow(ll a,ll n,ll p) { ll ret=1,A=a; for(; n ; A=(A*A)%p,n>>=1) if(n & 1)ret=(ret*A)%p; return ret; } void init_factorial(ll p) { factorial[0] = 1; for(ll i = 1;i <= p;i++)factorial[i] = factorial[i-1]*i%p; } ll C(ll a,ll k,ll p) { ll re = 1; for(; a && k ; a /= p , k /= p){ ll aa = a%p;ll bb = k%p; if(aa < bb) return 0; re = re*factorial[aa]*mod_pow(factorial[bb]*factorial[aa-bb]%p,p-2,p)%p; } return re; } ll Lucas(ll a,ll k ,ll p){ if(a<0 || k<0 || a<k)return 0; else return C(a,k,p); } int main(){ init_factorial(11); cout<<"take 2 candies in box which has 5 and mod 5 ____"<<Lucas(5,2,11)<<endl; cout<<"take 3 candies in box which has 7 and mod 5 ____"<<Lucas(7,3,11)<<endl; cout<<"wrong input : "<<Lucas(-1,-2,11)<<endl; cout<<"wrong input : "<<Lucas(3,9,11)<<endl; cout<<"wrong input : "<<Lucas(3,-2,11)<<endl; return 0; }
|