【poj1006-biorhythms】中国剩余定理

时间:2023-11-20 00:01:50

http://poj.org/problem?id=1006

题意:中国剩余定理的裸题。

题目可转化为求最小的x满足以下条件:

x%23=a;
x%28=b;
x%33=c;

关于中国剩余定理可看我昨天的博文:http://www.cnblogs.com/KonjakJuruo/p/5176417.html

//poj1006
/*
x%23=a;
x%28=b;
x%33=c;
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std; int tx,ty;
/*
void exgcd(int a,int b)
{
if(b==0) {tx=1,ty=0;return ;}
exgcd(b,a%b);
int x=ty,y=tx-(a/b)*ty;
tx=x;ty=y;
}
*/
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
int T=;
while()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a==- && b==- && c==- && d==-) return ;
int x=*a**;
int y=-*b**;
int z=*c**;
int g=**;
int ans=(x+y+z)%g;
while(ans-d <= ) ans+=g;
while(ans-d > g) ans-=g;
printf("Case %d: the next triple peak occurs in %d days.\n",++T,ans-d);
}
return ;
}