Lucas theorem (Modulo of a large number of groups) and lucas Theorem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.