枚举
View Code
//poj1006 #include <iostream> using namespace std; int a, b, c, d, t, dd; void work() { a %= 23; b %= 28; c %= 33; dd = d; while (1) { d++; if (d % 23 == a && d % 28 == b && d % 33 == c) { printf("Case %d: the next triple peak occurs in %d days.\n", t, d - dd); return; } } } int main() { //freopen("t.txt", "r", stdin); t = 0; while (cin >> a >> b >> c >> d) { t++; if (a == -1 && b == -1 && c == -1 && d == -1) break; work(); } return 0; }