POJ 1006 Biorhythms [中国剩余定理]
2018-01-11 09:54
375 查看
题意
给出a,b,c,d,求最小的S满足:S≡a(mod 23)
S≡b(mod 28)
S≡c(mod 33)
输出S-d
题解
orz zzk 中国剩余定理直接求这个方程组就好了
#include<cstdio> #include<algorithm> #define T 21252 using namespace std; int s,ans,a[4],b[4]={0,23,28,33}; int exgcd(int a,int b,int &x,int &y){ if(!b){ x=1,y=0; return a; } int r=exgcd(b,a%b,x,y),t; t=x,x=y,y=t-a/b*y; return r; } inline int China(int n){ int res=0; for(int i=1;i<=n;++i){ int x,y,w=T/b[i];exgcd(w,b[i],x,y); res=(res+w*x*a[i])%T; } return (res+T)%T; } int main(){ // freopen("testdata.in","r",stdin); // freopen("testdata.out","w",stdout); int test=0; while(~scanf("%d%d%d%d",&a[1],&a[2],&a[3],&s)){ if(a[1]==-1) break; ans=(China(3)-s+T)%T; printf("Case %d: the next triple peak occurs in %d days.\n",++test,ans<=0?ans+T:ans); } return 0; }
相关文章推荐
- POJ 1006 Biorhythms (数论-中国剩余定理)
- 中国剩余定理(CRT 孙子定理)——Biorhythms(POJ 1006)
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
- POJ 1006 Biorhythms (数论-中国剩余定理)
- poj1006_Biorhythms_扩展欧几里得_中国剩余定理
- POJ 1006 Biorhythms 中国剩余定理
- POJ 1006 Biorhythms【中国剩余定理】
- |poj 1006|中国剩余定理|Biorhythms
- poj1006 Biorhythms中国剩余定理
- poj 1006 Biorhythms 中国剩余定理
- 中国剩余定理 POJ 1006 Biorhythms
- POJ 1006 ——Biorhythms 中国剩余定理模板
- POJ 1006 Biorhythms --中国剩余定理(互质的)
- POJ1006 Biorhythms(生理周期,中国剩余定理详述)
- poj 1006 Biorhythms(中国剩余定理的应用)
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
- POJ1006-Biorhythms 中国剩余定理
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
- poj1006 Biorhythms<中国剩余定理>
- POJ 1006 Biorhythms 中国剩余定理