您的位置:首页 > 其它

POJ 1006 Biorhythms 生理周期 中国剩余定理

2016-10-19 19:39 239 查看
链接 : POJ 1006 Biorhythms

中文: POJ 1006 生理周期

我通过 ζёСяêτ - 小優YoU 的博客学习, 不再赘述。

不过貌似有点错误, 应该是33 * 28 * x0 (=6) == 5544 吧……

我的代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

int main()
{
int p, e, i, d;
int cas = 0;
while(cin >> p >> e >> i >> d)
{
if(p == -1 && e == -1 && i == -1 && d == -1)
break;
cas ++;
int lcm = 23*28*33;
int n = (5544*p+14421*e+1288*i-d+lcm)%lcm;
if(n == 0)
n = lcm;
printf("Case %d: the next triple peak occurs in %d days.\n", cas, n);
}
return 0;
}

/*
已知(n+d)%23=p;   (n+d)%28=e;   (n+d)%33=i
使33×28×a被23除余1,用33×28×**8**=5544;
使23×33×b被28除余1,用23×33×19=14421;
使23×28×c被33除余1,用23×28×2=1288。
因此有(5544×p+14421×e+1288×i)% lcm(23,28,33) =n+d
又23、28、33互质,即lcm(23,28,33)= 21252;
所以有n=(5544×p+14421×e+1288×i-d)%21252
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: