poj 1006 中国剩余定理
来源:互联网 发布:大数据涂子沛pdf 编辑:程序博客网 时间:2024/06/06 09:46
用exgcd求逆元,数据很水,int不会爆
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#define fo(i,a,b) for(int i=a;i<=b;i++)#define fod(i,a,b) for(int i=a;i>=b;i--)using namespace std;int m[4],a[4],p,e,i;void exgcd(int a,int b,int &d,int &x,int &y){ if(b==0){d=a;x=1;y=0;return ;} exgcd(b,a%b,d,x,y); int t=x;x=y;y=t-(a/b)*y; }int getinv(int a,int mod) { int x,y,d; exgcd(a,mod,d,x,y); if(d==1) return (x%mod+mod)%mod; else return -1;}int crt(){ int M=1,ans=0; fo(i,1,3) M*=m[i]; for(int i=1;i<=3;i++) { int Mi=M/m[i]; ans=(ans+Mi*getinv(Mi,m[i])*a[i])%M; } return ans<0?ans+M:ans;}int main(){ int kase=0,d; while(scanf("%d%d%d%d",&p,&e,&i,&d)) { if(p==e&&e==i&&i==d&&d==-1) break; a[1]=p;a[2]=e;a[3]=i; m[1]=23;m[2]=28;m[3]=33; int ans=crt(); if(ans<=d) ans+=21252; printf("Case %d: the next triple peak occurs in %d days.\n",++kase,ans-d); } return 0;}
阅读全文
0 0
- POJ 1006 中国剩余定理
- POJ 1006 中国剩余定理
- POJ 1006 中国剩余定理
- 中国剩余定理POJ 1006
- POJ 1006 ( 中国剩余定理 )
- POJ-1006(中国剩余定理)
- poj 1006-中国剩余定理
- poj 1006 中国剩余定理
- POJ 1006 中国剩余定理
- Poj 1006 中国剩余定理
- POJ 1006 中国剩余定理
- poj 1006 中国剩余定理
- poj-1006 中国剩余定理
- POJ 1006 中国剩余定理
- poj 1006 中国剩余定理
- POJ 1006: 中国剩余定理
- poj 1006 中国剩余定理
- POJ 1006 中国剩余定理
- jquery学习-1
- oracle恢复删除的数据
- 微信小程序项目实例
- PL/SQL编程基础知识(一)
- 设计模式之观察者模式
- poj 1006 中国剩余定理
- 关于iOS禁止输入表情符号
- 2144-图结构练习——最小生成树
- 欢迎使用CSDN-markdown编辑器
- opencv学习笔记(2017年8月21日)之图像腐蚀操作
- Python3之subprocess模块
- 实验室论文作图,绘制粒子点
- vector<string>转为vector<int>
- Binder