Peking University 1006

Source: Internet
Author: User
Tags integer division

Question link: http://acm.pku.edu.cn/JudgeOnline/problem? Id = 1006

This question mainly uses the Chinese Remainder Theorem

1. remainder problem: in integer division, a number is divided by several pairs of mutual quality numbers at the same time. After an integer operator, there are remainder numbers, it is known that each divisor and its corresponding remainder are used to obtain the divisor that meets the conditions.

2. Chinese Remainder Theorem: D1, D2, D3 ...... DN is an integer of N pairs. If integer x is divided by them, the remainder is R1, R2, R3 ...... RN, then the X that meets the condition is X = R1 * R1 + R2 * r2 + ...... Rn * rn + R * D, where RI (I = 1, 2, 3 ...... N) to remove the public multiples of each interlace integer of DI, and the remainder of Ri to Di is 1, R is any integer, and D is the minimum public multiple of An interlace integer.

3. Here two theorems are given to find the RI:

A) add several integers. If only one of them cannot be divisible by a, their and also cannot be divisible by.

B) two numbers cannot be divisible. If the divisor is expanded or reduced by N times, and the divisor is not changed, the remainder is also expanded or reduced by N times.

 

In this question, the three cycles are 23, 28, and 33, and the big cycle is their smallest public multiple, that is, 21252. The given P, E, and I are actually the remainder, according to the three numbers, this is the day of a week, and then the final solution of the problem is determined based on the result. It is determined that it is the day of the week. It is known that the division and the corresponding remainder are the remainder of the Division. We can use the Chinese Remainder Theorem to solve the problem.

 

# Include <iostream>
Using namespace STD;

Int main ()
{
Freopen ("in.txt", "r", stdin );
Int M1, M2, M3, M4, C, res;
C = 1;
While (CIN> m1> m2> m3> M4 &&
! (M1 =-1 & M1 = m2 & M1 = m3 & M1 = M4 ))
{
Res = (5544 * m1 + 14421 * M2 + 1288 * m3-M4 + 21252) % 21252; // reduce M4 first and add 21252 to avoid possible Overflow
If (RES = 0)
Res = 21252;
Cout <"case" <C ++
<": The next Triple peak occurs in" <res <"days./N ";
}
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.