[POJ1006]Biorhythms(中国剩余定理)
2017-01-14 14:50
344 查看
题目描述
传送门题解
中国剩余定理模板题注意统计ni的时候如果想用y来统计那么应该是1-mi*y,因为用扩欧求的是不带符号的
代码
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; int Case,N,M,d,a,b,x,y,n[5],m[5],c[5]; void exgcd(int a,int b,int &x,int &y) { if (!b) x=1,y=0; else exgcd(b,a%b,y,x),y-=a/b*x; } int main() { m[1]=23;m[2]=28;m[3]=33;M=m[1]*m[2]*m[3]; while (~scanf("%d%d%d%d",&c[1],&c[2],&c[3],&d)) { if (c[1]==-1&&c[2]==-1&&c[3]==-1&&d==-1) return 0; for (int i=1;i<=3;++i) { a=M/m[i];b=m[i]; exgcd(a,b,x,y); x=((x%b)+b)%b; if (!x) x+=b; n[i]=a*x; } N=0; for (int i=1;i<=3;++i) N+=n[i]*c[i]; N-=d; N=(N%M+M)%M; if (!N) N+=M; printf("Case %d: the next triple peak occurs in %d days.\n",++Case,N); } }
相关文章推荐
- poj1006 Biorhythms(中国剩余定理)
- POJ1006 - Biorhythms(中国剩余定理)
- 数学-poj1006 (中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- poj 1006 Biorhythms (中国剩余定理模板)
- Biorhythms(中国剩余定理)
- poj 1006 Biorhythms(中国剩余定理)
- poj1006(中国剩余定理)
- uva 756 - Biorhythms(中国剩余定理)
- poj 1006 Biorhythms(中国剩余定理)
- POJ1006(中国剩余定理)
- POJ 1006 Biorhythms(中国剩余定理)
- POJ1006 Biorhythms【中国剩余定理】
- HDU 1370 Biorhythms(中国剩余定理)
- poj1006 生理周期(中国剩余定理)
- 九度OJ 1142:Biorhythms(生理周期) (中国剩余定理)
- 【学习笔记-中国剩余定理】POJ1006 Biorhythms
- poj 1006 Biorhythms(中国剩余定理)
- POJ 1006 - Biorhythms (中国剩余定理)
- POJ_1006_Biorhythms(中国剩余定理)