Chinese remainder theorem

Source: Internet
Author: User

< I prefer to do a summary, so many of the knowledge is found on the Internet and re-organized use, the main purpose is to deepen my personal understanding and summary, welcome to point out the mistakes, discuss together, progress together >

Information reference: https://zh.wikipedia.org/wiki/%E4%B8%AD%E5%9B%BD%E5%89%A9%E4%BD%99%E5%AE%9A%E7%90%86

"There is no known number, 33 of the remaining two, 55 of the remaining three, 77 of the remaining two." Asking for geometry? "This is the source of the Chinese remainder theorem, what does it mean?" That is, if the number of items, if three three number, there will be two, if five five numbers, there will be three, if it is 77, then there will be two, then how many of them? (Source wiki)

I would like to discuss this issue from a special to a general point;

The question can actually be abstracted to the mathematics problem as follows: Now we think, how can we find such a number x?

First we define A[1 2 3] = 2, 3, 2;m[1 2 3] = 3, 5, 7; We think, if there is such an x, then what is the nature of it? First it to meet the Mi modulus when the corresponding value of the AI, good then we from the programming cycle to think, whether there is a ti for ti% mi = ai, while ti% MJ (j! = i) = 0 if present, then we x can be equal to T1 + T2 + T3 (because In order to assign the module to TI separately, there are two values of 0) If so, how to construct? Well, at least we have a clue now. Then ti how to build, must first have an AI% mi = ai, then we can find a ti/ai, it satisfies ti/ai% mi = 1, at the same time by ti% MJ (j! = i) = 0, ti/ai% mi = 1, Ti% mi = ai can get this T I/ai This item has a property of ti/ai% MJ = 0; Okay, now about

Ti/ai This item has a certain nature: Ti/ai% MJ =0, ti/ai% mi = 1, so through the structure of the TI/AI is a multiple of MJ, at the same time, it will be in MI under two reciprocal of the product, so the use of MI for the multiplication of MI, but excluding item I, while making Ti = mi mode m I's Number theory reciprocal, also that satisfies ti * Mi = 1 (mod mi), Ti/ai = Ti * MI;

(here to add a description, what is the number of modulo mi countdown, that is, when the MI is determined, you can use the TI * mi% mi = = 1 of the figure, this can be cycled to seek, the maximum number of cycles is Mi, because Ti < mi, hit a minimal ti on it can be)

That's now ok ti = ai * ti * Mi, while for (S) we have a ti * mi% mi = 1, which means

So you can determine T1, T2, T3, you can also find X.

For the general proof of the principle, I think the proof on the wiki is very good.

There is one to add, why x1-x2 ==0 (mod mi) and 22 mi between coprime can be released between the two solutions of the number of related m-multiples? is because x1-x2 = = 0 (mod mi) is indicative of x1-x2

At least there is a total of MI as an approximate (the above equation is set up for all MI), and M is the product of all MI, so you can get x1-x2 is a multiple of M, x1-x2 <= m (assuming x1 > x2)

Recommended topics Exercise: POJ 1006

Chinese remainder theorem

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.