Skip to content

Instantly share code, notes, and snippets.

@bowbowbow
Created October 25, 2015 18:54
Show Gist options
  • Save bowbowbow/72f9fecfcfb92f6cfc62 to your computer and use it in GitHub Desktop.
Save bowbowbow/72f9fecfcfb92f6cfc62 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define MAXN 2010
int binomial[MAXN][MAXN];
ll N, K, M;
int main(){
cin >> N >> K >> M;
for(int i=0; i<M; i++){
binomial[i][0] = 1;
for(int j=1; j<=i; j++)
binomial[i][j] = (binomial[i-1][j-1] + binomial[i-1][j])%M;
}
int ret = 1;
while(N || K){
ret *= binomial[N%M][K%M];
N /= M, K /= M;
ret %= M;
}
cout << ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment