Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u

Description

Input

Output

Case 1: the next triple peak occurs in 1234 days.

Sample Input

0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1

Sample Output

Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.

Hint

Translator

Source

p + 23 * k1 = e + 28 * k2 = i + 33 * k3 = ans（k1, k2, k3为任意非零自然数）

ans % 23 = p, ans % 28 = e, ans % 33 = i

1. 爆搜

1)需要从d + 1开始枚举，因为原题要求不包括给定时间
2)不能将21252作为上界。比如1 1 1 2这组数据，会搜到21253
3)读入后就需要将p, e, i, d分别对23, 28, 33, 21252取模
AC代码：
#include <cstdio>
using namespace std;
int P, E, I, D;
void solve(int cas)
{
int res;
for (res = D + 1;; res++)
if (res % 23 == P && res % 28 == E && res % 33 == I)
break;
res -= D;
if (!res)
res = 21252;
printf("Case %d: the next triple peak occurs in %d days.\n", cas, res);
}
int main()
{
int cas = 1;
while (scanf("%d%d%d%d", &P, &E, &I, &D) == 4)
{
if (P == -1 && E == -1 && I == -1 && D == -1)
break;
P %= 23;
E %= 28;
I %= 33;
D %= 21252;
solve(cas++);
}
return 0;
}

2. 正解，中国剩余定理