题目概述:
已知 三个变量 p e i ;为三个周期循环的起始时间,其周期分别为23 28 33。
求三个循环同时结束时,距d的时间。
即为求三个同余方程 x=p mod 23 x=e mod 28 x=p mod 33;
利用中国剩余定理可得 解 x=(1288 * c + 14421 * b + 5544 * a ) % 21252。
#include<iostream>
using namespace std;
int main()
{
int a, b, c, d,i=1;
while (cin >> a >> b >> c >> d, d != -1)
{
a %= 23;
b %= 28;
c %= 33;
int out = (1288 * c + 14421 * b + 5544 * a - d + 21252) % 21252;
if (out==0)
{
cout << "Case "<<i<<": the next triple peak occurs in " << 21252 << " days." << endl;
}
else
{
cout << "Case " << i << ": the next triple peak occurs in " << out << " days." << endl;
}
i++;
}
}