Binomial Modulo Small Prime
Compute C(N, K) modulo a prime P, where N and K are enormous (up to 1018) but P is small.
Input: one line with three integers N, K, P.
Output: C(N, K) mod P.
Constraints:
- 0 ≤ K ≤ N ≤ 1018
- 2 ≤ P ≤ 5000, P prime
Sample Tests
Input 1
10 3 7
Output 1
1
Input 2
5 0 11
Output 2
1
Discussion (opens after you solve — no spoilers before)
No comments yet.