POJ 1006 生理周期

分析:中国剩余定理(注意结果要大于d即可)

代码:

#include<iostream>
#include<cstdio>
using namespace std;
int n1, n2, n3, n;
void solve() {
    n1 = 28*33;
    while(n1%23 != 1) n1 += 28*33; 
    n2 = 23*33;
    while(n2%28 != 1) n2 += 23*33; 
    n3 = 23*28;
    while(n3%33 != 1) n3 += 23*28; 
    n = 23*28*33;
}
int main() {
    int Case = 1;
    solve(); 
    while(1) {
        int p, e, i, d;
        scanf("%d%d%d%d", &p, &e, &i, &d);
        if(p == -1 && e == -1 && i == -1 && d == -1) break;
        int ans = (n1*p+n2*e+n3*i)%n;
        while(ans <= d) ans += n;  
        printf("Case %d: the next triple peak occurs in %d days.\n", Case++, ans-d);
    }
    return 0;
}

 

posted on 2018-04-09 16:52  kindleheart  阅读(191)  评论(0编辑  收藏  举报