POJ 1006 Biorhythms

Source: Internet
Author: User

Biorhythms
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 117289 Accepted: 36793

Description

Some people believe that there be three cycles in a person's life that's start the day he or she's born. These three cycles is the physical, emotional, and intellectual cycles, and they have periods of lengths, D, and Ays, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes would be sharper and concentration would be easier.
Since the three cycles has different periods, the peaks of the three cycles generally occur at different times. We would like-to-determine when a triple peak occurs (the peaks of all three cycles occur in the "Same day") for any person. For each cycle, you'll be given the number of days from the beginning of the current year at which one of its peaks (no T necessarily the first) occurs. You'll also be given a date expressed as the number of days from the beginning of the current year. You task was to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is ten and the next triple peak occurs on day, the answer was 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.

Input

You'll be given a number of cases. The input for each case consists of a line of four integers p, E, I, and D. The values P, E, and I are is the number of days from the beginning of the which the physical, emotional, and Intellectual cycles peak, respectively. The value D is the given date and could be smaller than any of P, E, or I. All values is non-negative and at most 365, and your may assume that a triple peak would occur within 21252 days of the GIV En date. The end of input is indicated by a line in which p = e = i = d =-1.

Output

For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in The form:

Case 1:the Next triple peak occurs in 1234 days.

Use the plural form "days" even if the answer is 1.

Sample Input

0 0 0 00 0 0 1005 20 34 3254 5 6 7283 102 23 320203 301 203 40-1-1-1-1

Sample Output

Case 1:the Next triple peak occurs in 21252 days. Case 2:the Next triple peak occurs in 21152 days. Case 3:the Next triple peak occurs in 19575 days. Case 4:the Next triple peak occurs in 16994 days. Case 5:the Next triple peak occurs in 8910 days. Case 6:the Next triple peak occurs in 10789 days.

Source

East Central North America 1999

Chinese remainder theorem

Study article: http://www.cnblogs.com/walker01/archive/2010/01/23/1654880.html

1#include <iostream>2 using namespacestd;3 intgcdintAintb) {4     if(b==0){5         returnA;6     }7     returnGCD (b,a%b);8 }9 voidFindintAintBintc) {//Ten     intt,l; Onel=b*c/gcd (b,c); At=1; -      while(t*l%a!=1){ -t++; the     } -cout<<a<<" "<<t*l<<Endl; - } - intMain ()// at a + { -     intp,e,i,d; +     intTime=1; A     //find (23,28,33);//5544 at     //find (28,33,23);//14421 -     //find (33,23,28);//1288 -      while(cin>>p>>e>>i>>d) -     { -         if(p==-1&& e==-1&& i==-1&& d==-1) -              Break; in         intlcm=21252;//LCM (23,28,33) -         intN= (5544*p+14421*e+1288*i-d+21252)%21252; to         if(n==0) +n=21252; -cout<<" Case"<<time++<<": The next triple peak occurs in"<<n<<"Days ."<<Endl; the     } *     return 0; $}

POJ 1006 Biorhythms

Related Keywords:

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.