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

来源:互联网 发布:淘宝二手都要3c认证吗 编辑:程序博客网 时间:2024/05/17 00:00

链接 : 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 又232833互质,即lcm(23,28,33)= 21252;所以有n=(5544×p+14421×e+1288×i-d)%21252*/
0 0
原创粉丝点击