分析:中国剩余定理(注意结果要大于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; }
作者:kindleheart
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。