#include<stdio.h>
#define r1 23
#define r2 28
#define r3 33
int gcd(int a,int b){
int t1 = a,t2 = b,t;
while(a % b != 0){
t = a%b;
a = b;
b = t;
}
return t1 / b * t2;
}
int computeRN(int a,int b,int r) {
int t,i;
t = gcd(a,b);
if(t % r == 1) {
return t;
} else {
for(i = 2;;i++)
if(i * t % r == 1)
return i * t;
}
}
int main() {
int p,e,i,d,day,time = 1;
int RD,R1,R2,R3;
while(scanf("%d %d %d %d",&p,&e,&i,&d) != EOF) {
if(p == -1) break;
RD = gcd(gcd(r1,r2),r3);
R1 = computeRN(r2,r3,r1);
R2 = computeRN(r1,r3,r2);
R3 = computeRN(r1,r2,r3);
day = (p * R1 + e * R2 + i * R3 + RD - d) % RD;
day = day ? day : RD;
printf("Case %d: the next triple peak occurs in %d days.\n",time++,day);
}
}
分享到:
相关推荐
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53539 Accepted: 15282 Description Some people believe that there are three cycles in a person's life that start the day he or ...
《POJ1006-Biorhythms:深入解析与应用中国剩余定理》 在计算机编程领域,解决算法问题是我们提升技术能力的重要途径。POJ1006-Biorhythms是一个典型的算法挑战,它引入了数学中的一个重要概念——中国剩余定理。...
在压缩包文件的名称"BiorhythmsPoj1006"中,"Biorhythms"可能是指生物节律,这可能意味着问题与人的身体、情绪或智力状态的周期性变化有关。在编程竞赛中,这样的问题可能要求参赛者模拟或计算某种基于时间周期的...
小的 在这发个代码呵呵 北大ACM的1006题答案呵呵 帮助菜鸟啊呵呵
1160 Biorhythms 简单题 1163 The Staircases 简单题 1177 K-Magic Number 简单题 1184 Counterfeit Dollar 简单题 1182 Keeps Going and Going and ... 简单题,我喜欢:) 1284 Perfection 简单题 1272 ...
1160 Biorhythms 简单题 1163 The Staircases 简单题 1177 K-Magic Number 简单题 1184 Counterfeit Dollar 简单题 1182 Keeps Going and Going and ... 简单题,我喜欢:) 1284 Perfection 简单题 1272 ...