题目:Biorhythms
思路:
中国剩余定理模板题。
代码:
#include<bits/stdc++.h>
using namespace std;
#define A 23
#define B 28
#define C 33
#define lcm (A*B*C)
#define mdA B*C
#define mdB A*C
#define mdC B*A
int a,b,c,d;
int main(){
int T=0;
while(~scanf("%d%d%d%d",&a,&b,&c,&d)&&~a){
int x,y,z;
for(x=1;(mdA*x)%A!=1;x++);
for(y=1;(mdB*y)%B!=1;y++);
for(z=1;(mdC*z)%C!=1;z++);
x=x*mdA*a;
y=y*mdB*b;
z=z*mdC*c;
int ans=(x+y+z+lcm-d)%lcm;
if(ans==0) ans=lcm;
printf("Case %d: the next triple peak occurs in %d days.\n",++T,ans);
}
return 0;
}