#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【中国剩余定理】 解题报告+AC代码
行业教育软件-学习软件-软件下载_学习软件_电脑学习_Natural Biorhythms 3.031免费下载.zip
小的 在这发个代码呵呵 北大ACM的1006题答案呵呵 帮助菜鸟啊呵呵
显示您与出生日期的照片墙(BioRhythms和所有那个...)的兼容性。百分;) 是的,不要忘记在设置中指定出生日期。 阅读更多关于Wiki或http://cmpati.me 愉快的使用! :) 用于搜索的标签:Fotostrana,BioRhythms,...
生物节律将在Cleve's Corner博客版中进行讨论。 请参阅http://blogs.mathworks.com/cleve/biorhythms 。
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 ...