【poj1006-biorhythms】中国剩余定理
生活随笔
收集整理的這篇文章主要介紹了
【poj1006-biorhythms】中国剩余定理
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
http://poj.org/problem?id=1006
題意:中國剩余定理的裸題。
題目可轉(zhuǎn)化為求最小的x滿足以下條件:
x%23=a;
x%28=b;
x%33=c;
關(guān)于中國剩余定理可看我昨天的博文: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; } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/KonjakJuruo/p/5178510.html
總結(jié)
以上是生活随笔為你收集整理的【poj1006-biorhythms】中国剩余定理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: db2 jdbc连接字符串中 指定cur
- 下一篇: django URL路由基础