您的位置:首页 > 其它

Biorhythms (POJ1006)

2016-05-10 14:38 323 查看
题目概述:

已知 三个变量 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++;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  组合数学 poj