Combination
InterviewTime limit1sMemory limit256 MB
Compute N choose R modulo 1,000,000,007 for 0 ≤ R ≤ N ≤ 1,000,000 using a prime modulus.
- Level
Medium4 of 10
- Topics
- Math, Number theory, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
In an introductory statistics class, Junha was given an assignment to count the number of shortest paths from the bottom-left corner to the top-right corner of a grid wide and tall.
As you know, the answer is . Just looking at it makes you excited to compute a combination, right? It turns out that computing combinations can be done with code too. Let's solve the assignment with code!
Input
The first line gives and . ()
Output
Print the value of modulo . ( is prime)