POJ1006、hdu1370

思路:中国剩余定理。纯粹的用暴力求逆元。

 1 #include<iostream>
 2 #include<string.h>
 3 #include<string>
 4 #include<algorithm>
 5 #include<stdio.h>
 6 #include<iomanip>
 7 #include<cmath>
 8 #include<map>
 9 using namespace std;
10 void Find(int &x,int &y,int &z){
11     while(23*28*x%33!=1){
12         x++;
13     }
14     while(23*33*y%28!=1){
15         y++;
16     }
17     while(28*33*z%23!=1){
18         z++;
19     }
20 }
21 int main(){
22     int x,y,z;
23     x=y=z=1;
24     Find(x,y,z);
25     int p,e,i,d,times;
26     times=1;
27     //int T;
28     //cin>>T;  //hdu需要多这两行
29     while(cin>>p>>e>>i>>d){
30         if(p==-1&&e==-1&&i==-1&&d==-1){
31             break;
32         }
33         int ans=(z*33*28*p+y*23*33*e+x*23*28*i-d+23*28*33)%(28*23*33);
34         if(ans==0) ans=28*23*33;
35         cout<<"Case "<<times++<<": the next triple peak occurs in "<<ans<<" days."<<endl;
36     }
37     return 0;
38 }
原文地址:https://www.cnblogs.com/ISGuXing/p/8451532.html