Created
October 25, 2015 18:54
-
-
Save bowbowbow/72f9fecfcfb92f6cfc62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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