1006 biorhythms

思路:与求最大公约数基本方法一致。虽然起点不同但终点仍旧一致,起点也可以求出相减为0的情况。

注意:不需要用暴力枚举的方法。我们在进行枚举时筛选。以最小的23进行倍数增长一次试验。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5 int main(){
 6     int p,i,e,d,count=1;
 7     while(true){
 8         cin>>p>>i>>e>>d;
 9         p%=23;i%=28;e%=33;
10         int t,h=0;
11         if(p==-1)
12             break;
13         while(true){
14             t=p+h++*23;
15             if(t<=d)continue;
16             if((t-i)%28==0&&(t-e)%33==0){
17                 //printf("Case %d: the next triple peak occurs in %d days.\n", count++, t - d);
18                 cout<<"Case "<<count++<<": the next triple peak occurs in "<<t-d<<" days."<<endl;
19                 break;
20             }
21         }
22     }
23     return 0;
24 }

 

posted on 2019-09-11 11:05  姜姜糖  阅读(170)  评论(0编辑  收藏  举报