Poj 1006

就是中国剩余定理的应用……

幸好我学了数学基础

 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4     int p,e,i,d;
 5     int k;
 6     int count=1;
 7     while(cin>>p>>e>>i>>d){
 8         if(p==-1&&e==-1&&i==-1&&d==-1){
 9             break;
10         }
11         k=0;
12         p=p%23;
13         e=e%28;
14         i=i%33;
15         k=(k+(p*5544))%21252;
16         k=(k+(e*14421))%21252;
17         k=(k+(i*1288))%21252;
18         if(k==0){
19             k+=21252;
20         }
21         if(d==k){
22             cout<<"Case "<<count<<": the next triple peak occurs in "<<21252<<" days."<<endl;
23         }
24         else if(k>d){
25             cout<<"Case "<<count<<": the next triple peak occurs in "<<k-d<<" days."<<endl;
26         }
27         else{
28             cout<<"Case "<<count<<": the next triple peak occurs in "<<k-d+21252<<" days."<<endl;
29         }
30         count++;
31     }
32 }

 

posted @ 2017-01-25 20:56  水野玛琳  阅读(107)  评论(0编辑  收藏  举报