http://poj.org/problem?id=1006
题意:
(n+d) % 23 = p ;
(n+d) % 28 = e ;
(n+d) % 33 = i ;
求最小的n。
思路:
这道题就是中国剩余定理。
#include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cmath> using namespace std; int n; int main() { //freopen("D:\txt.txt", "r", stdin); int p, e, i, d; int kase = 0; while (cin >> p >> e >> i >> d) { if (p == -1 && e == -1 && i == -1 && d == -1) break; int lcm = 21252; int n = (5544 * p + 14421 * e + 1288 * i - d + 21252) % 21252; if (n == 0) n = 21252; cout << "Case " << ++kase << ": the next triple peak occurs in " << n << " days." << endl; } return 0; }