1006-biorhythms (Chinese remainder theorem)

Source: Internet
Author: User

One, test instructions: Chinese in upper right corner.
Second, the idea:
1, the equations are derived from test instructions
2, using the Chinese remainder theorem to solve
3, find the smallest positive integer
Three, step:
1, the equations are derived from test instructions

(n+d)% (p);
(n+d)% = e;
(n+d)% = i;
2, China remainder theorem solution
I, from the common multiple of 23 and 28 to find X, and meet x%33 = 1, x=1288
II, find y from the common multiple of 23 and 33, and meet y%28 = 1, y=14421
III, find z from the common multiple of 28 and 33, and meet z%23 = 1, z=5544
Iiii,s = (n+d) = (5544*p+14421*e+1288*i)% LCM (23,28,33); LCM for least common multiple = 21252;
3, finding the minimum positive integer solution
I, prevent n is negative: n= (n+21252)%21252
Note that when n=0, the result is output 21252.

1#include <iostream>2 using namespacestd;3 4 intMain () {5     intP,e,i,d,n,s,l=1;6      while(cin>>p>>e>>i>>d) {7         if(p==-1&&e==-1&&i==-1&&d==-1) Break;8         intN= (5544*p+14421*e+1288*i)%21252-D;9N= (n+21252)%21252;//prevent S from being negativeTen         if(n==0) Onen=21252; Aprintf"Case %d:the Next triple peak occurs in%d days.\n", l++, n); -     } -     return 0; the}
View Code

1006-biorhythms (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.