标签:
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=0; while(1) { int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); if(a==-1 && b==-1 && c==-1 && d==-1) return 0; int x=6*a*28*33; int y=-9*b*23*33; int z=2*c*23*28; int g=23*28*33; int ans=(x+y+z)%g; while(ans-d <= 0) ans+=g; while(ans-d > g) ans-=g; printf("Case %d: the next triple peak occurs in %d days.\n",++T,ans-d); } return 0; }
标签:
原文地址:http://www.cnblogs.com/KonjakJuruo/p/5178510.html