Lucas theorem (Modulo of a large number of groups) and lucas Theorem
First, we give the Lucas theorem:
A and B are non-negative integers, and p are prime numbers. AB is written in p Notation: A = a [n] a [n-1]... a [0], B = B [n] B [n-1]... B [0].
Then, the combination numbers C (A, B) and C (a [n], B [n]) * C (a [n-1], B [n-1]) *... * C (a [0], B [0]) mod p with Remainder
That is, Lucas (n, m, p) = c (n % p, m % p) * Lucas (n/p, m/p, p)
The proof of this theorem is not very simple. I always wanted to find a good proof, but I didn't find it. I saw a problem-solving report yesterday. I can basically understand what happened to this Lucas theorem, specifically:
To solve n! % P is used as an example to segment n, where each p segment returns the same result. However, we need to separate p, 2 p,... at the end of each segment and extract p. We will find that the remaining number is exactly (n/p )!, It is equivalent to dividing it into a subproblem, so that it can be solved recursively.
This is to process n separately! Of course C (n, m) is n! /(M! * (N-m )!), If each factorial is processed using the above method, it is the Lucas theorem. Note that p here is necessary for prime numbers.
Lucas's maximum data processing capability is p at around 10 ^ 5, which cannot be larger. hdu 3037 is 10 ^ 5!
For the modulo of a large group, if n and m are not greater than 10 ^ 5, the reverse element method can be used. If n, m is greater than 10 ^ 5, p <10 ^ 5 is required. In this case, the Lucas theorem is used to convert n, m to a solution less than 10 ^ 5.
Then I won't be able to get Big Data!
Recommendation: hdu 3037