传送门:http://acm.jlu.edu.cn/joj/showproblem.php?pid=1491
一道中国剩余定理.....不懂的可以去百度一下。
题意就是(n + d) % 23 = p; (n + d) % 28 = e; (n + d) % 33 = i;
33 * 28 * 8 % 23 = 1;
23 * 33 * 19 % 28 = 1;
23 * 28 * 2 % 33 = 1;
所以 n = (5544 * p + 14421 * e + 1288 * i - d + 23 * 28 * 33) % (23 * 28 * 33)
代码:
#include <cstdio>
using namespace std;
int main()
{
int p, e, i, d, n;
int Case = 1;
while (scanf("%d%d%d%d", &p, &e, &i, &d) && p != -1)
{
n = (5544 * p + 14421 * e + 1288 * i - d + 21252) % 21252;
if (n == 0) n = 21252;
printf("Case %d: the next triple peak occurs in %d days.\n", Case++, n);
}
return 0;
}