Poj1006 Chinese Residue Theorem

Source: Internet
Author: User

China Remainder Theorem
Example 1: What is the minimum value of A number divided by 3 to 1, 4 to 2, and 5 to 4?
The numbers 3, 4, and 5 are mutually qualitative. Then [4, 5] = 20; [3, 5] = 15; [3, 4] = 12; [3, 4, 5] = 60. In order to divide 20 by 3 to 1, 20 × 2 = 40; so that 15 is divided by 4 to 1, 15 × 3 = 45; so that 12 is divided by 5 to 1, use 12 × 3 = 36. Then, 40 × 1 + 45 × 2 + 36 × 4 = 274, because, 274> 60, so, 274-60 × 4 = 34, is the number of requests.

Example 2: What is the minimum value of A number divided by 3, 2, 7, 4, and 8? The numbers 3, 7, and 8 are mutually qualitative. Then [168] = 56; [] = 24; [] = 21; [, 8] =. In order to divide 56 into 3 and 1, 56 × 2 = 112; make 24 to 7 and 24 × 5 = 120. So that 21 is divided by 8 and 1, 21 × 5 = 105; then, 112 × 2 + 120 × 4 + 105 × 5 = 1229, because, 1229> 168, so, 1229-168x7 = 53, which is the number of requests.

Example 3: divide a number by 5 plus 4, divide by 8 plus 3, and divide by 11 plus 2 to obtain the minimum natural number that meets the conditions. The numbers 5, 8, and 11 are mutually qualitative.
Then [8, 11] = 88; [5, 11] = 55; [5, 8] = 40; [5, 8, 11] = 440. In order to make 88 be divided by 5 and 1, 88 × 2 = 176 is used;
So that 55 is divided by 8 to 1, with 55 × 7 = 385; so that 40 is divided by 11 to 1, with 40 × 8 = 320. Then, 176 × 4 + 385 × 3 + 320 × 2 = 2499. Because, 2499> 440, 2499-440 × 5 = 299 is the desired number.

Example 4: A grade student has five more people in a row per 9 people, one more person in a row per 7 people, and two more people in a row per 5 people, how many people are there in this grade?
(Questions asked by happy 123 teachers) The numbers 9, 7, and 5 are of mutual quality. Then [7, 5] = 35; [9, 5] = 45; [9, 7] = 63;
(9, 7, 5) = 315. In order to divide 35 by 9 to allow 1, 35x8 = 280; 45 is divided by 7 to allow 1, 45x5 = 225; 63 is divided by 5 to allow 1,
Use 63 × 2 = 126. Then, 280 × 5 + 225 × 1 + 126 × 2 = 1877, because, 1877> 315, so, 1877-315 × 5 = 302, is the desired number.

Example 5: There is a grade student. There are 6 more people in each 9-person row. There are 2 more people in each 7-person row, and 3 more people in each 5-person row, how many people are there in this grade?
The numbers 9, 7, and 5 are mutually qualitative. Then [7, 5] = 35; [9, 5] = 45; [9, 7] = 63; [9, 7, 5] = 315. In order to divide 35 by 9 to allow 1, 35x8 = 280; 45 is divided by 7 to allow 1, 45x5 = 225; 63 is divided by 5 to allow 1, use 63 × 2 = 126. Then, 280 × 6 + 225 × 2 + 126 × 3 = 2508, because, 2508> 315, therefore, 2508-315 × 7 = 303 is the desired number. (In Example 5 and in example 4, the divisor is the same, and the remainder is the same. The difference is the last two steps .)

# Include <iostream>
Using namespace STD;
Int main ()
{
Int P, E, I, D, Count = 0;

While (CIN> P> E> I> D, P! =-1)
{
Int day = 21252;
Count ++;
Int A, B, C, x, y, z;

A = P #;
B = E (;
C = I3;

For (Int J = 1; j ++)
{
If (924 * J # = 1)
{
X = 924 * J;
Break;
}
}
For (Int J = 1; j ++)
{
If (759 * j (= 1)
{
Y = 759 * J;
Break;
}
}
For (Int J = 1; j ++)
{
If (644 * J3 = 1)
{
Z = 644 * J;
Break;
}
}
Int S;
S = x * A + y * B + z * C;
Day = s! 252-d;
If (day <= 0)
Day ++ = 21252;
Cout <"case" <count <": The next Triple peak occurs in" <day <"days." <Endl;
}

System ("pause ");
Return 0;
}

 

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.