#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int m[4], a[4];
int M;
void Ex_Gcd(int a, int b, int &d, int &x, int &y)
{
if(b == 0)
{
x = 1, y = 0;
d = a;
return ;
}
else
{
Ex_Gcd(b, a%b, d, x, y);
int temp = x;
x = y;
y = temp - (a/b) * y;
}
}
int China( int r )
{
int i;
M = 1;
int Mi, x0, y0, d, ans = 0;
for(i = 1; i <= r; ++i)
M *= m[i];
for(i = 1; i <= r; ++i)
{
Mi = M / m[i];
Ex_Gcd(Mi, m[i], d, x0, y0);
ans = (ans + Mi * x0 * a[i]) % M;
}
if(ans < 0)
ans += M;
return ans;
}
int main()
{
int kcase = 1;
int p, e, i, d;
while(~scanf("%d %d %d %d", &p, &e, & i, &d))
{
if(p == -1 && e == -1 && i == -1 && d == -1)
break;
a[1] = p, a[2] = e, a[3] = i;
m[1] = 23, m[2] = 28, m[3] = 33;
int ans = China( 3 );
while(ans <= d)
ans += M;
cout<<"Case "<<kcase++<<": the next triple peak occurs in "<<ans-d<<" days."<<endl;
}
return 0;
}
poj 1006 Biorhythms
最新推荐文章于 2024-01-03 16:43:35 发布