Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int mod = 666013;
- int invers(int x) {
- int exp = mod - 2, ans = 1;
- while(exp) {
- if(exp & 1)
- ans = ans * x % mod;
- x = x * x % mod;
- exp >>= 1;
- }
- return ans;
- }
- int nck(int N, int K) {
- if(N < K)
- return 0;
- int st = 1, dr = N, other = K;
- if(K < N - K) {
- st = N - K + 1;
- other = K;
- }
- else {
- st = K + 1;
- other = N - K;
- }
- int ans = 1;
- for(int i = st; i <= dr; ++i)
- ans = ans * i % mod;
- int other_p = 1;
- for(int i = 1; i <= other; ++i)
- other_p = other_p * i % mod;
- ans = ans * invers(other_p) % mod;
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement