forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1006(AC).cpp
55 lines (47 loc) · 875 Bytes
/
POJ1006(AC).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;
int main()
{
int p;
int e;
int i;
int d;
const int tp = 23;
const int te = 28;
const int ti = 33;
int kp;
int ke;
int ki;
int next;
int ci;
ci = 0;
while(true){
if(scanf("%d%d%d%d", &p, &e, &i, &d) != 4){
break;
}else if(p == -1 && e == -1 && i == -1 && d == -1){
break;
}else{
++ci;
}
kp = te * ti;
while(kp % tp != 1){
kp += te * ti;
}
ke = ti * tp;
while(ke % te != 1){
ke += ti * tp;
}
ki = tp * te;
while(ki % ti != 1){
ki += tp * te;
}
next = (kp * p + ke * e + ki * i) % (tp * te * ti);
if(d == next){
printf("Case %d: the next triple peak occurs in %d days.\n", ci, tp * te * ti);
}else{
printf("Case %d: the next triple peak occurs in %d days.\n", ci, (next - d + tp * te * ti) % (tp * te * ti));
}
}
return 0;
}