CRT用于求解一元线性同余方程组(模数互质),实际上模数不互质我们也可以解决,在之前的某篇文章里提过。如下

http://www.cnblogs.com/autsky-jadek/p/6596010.html

#include<cstdio>
using namespace std;
typedef long long ll;
ll m[4],a[4],D,ans;
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){
if(!b){
d=a;
x=1;
y=0;
}
else{
exgcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
void CRT(int r){
ll M=1,Mi,x0,y0,d;
ans=0;
for(int i=1;i<=r;++i){
M*=m[i];
}
for(int i=1;i<=r;++i){
Mi=M/m[i];
exgcd(Mi,m[i],d,x0,y0);
ans=(ans+Mi*x0*a[i])%M;
}
if(ans<=D){
ans+=M;
}
}
int main(){
// freopen("poj1006.in","r",stdin);
int zu=0;
m[1]=23; m[2]=28; m[3]=33;
while(1){
++zu;
scanf("%lld%lld%lld%lld",&a[1],&a[2],&a[3],&D);
if(a[1]==-1 && a[2]==-1 && a[3]==-1 && D==-1){
break;
}
CRT(3);
printf("Case %d: the next triple peak occurs in %lld days.\n",zu,ans-D);
}
return 0;
}

【数论】【中国剩余定理】poj1006 生理周期的更多相关文章

  1. 【同余方程组】POJ1006 生理周期

    同余方程组: 先来看一道题目:有物不知其数,三三数之剩二:五五数之剩三:七七数之剩二.问物几何?  然后我们可以做如下变换,设x为所求的数. x%3=2              x ≡ a1(%m1 ...

  2. poj1006生理周期(中国剩余定理)

    /* 中国剩余定理可以描述为: 若某数x分别被d1..….dn除得的余数为r1.r2.….rn,则可表示为下式: x=R1r1+R2r2+…+Rnrn+RD 其中R1是d2.d3.….dn的公倍数,而 ...

  3. [POJ1006]生理周期 (中国剩余定理)

    蒟蒻并不会中国剩余定理 交的时候还出现了PE的错误 下面是AC代码 #include<iostream> #include<cstdio> using namespace st ...

  4. poj1006生理周期(中国剩余定理)

    生理周期 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 139224   Accepted: 44687 Descripti ...

  5. poj1006 生理周期

    生理周期 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 138947   Accepted: 44597 Descripti ...

  6. POJ 1006 Biorhythms (数论-中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 111285   Accepted: 34638 Des ...

  7. 【bzoj1951】: [Sdoi2010]古代猪文 数论-中国剩余定理-Lucas定理

    [bzoj1951]: [Sdoi2010]古代猪文 因为999911659是个素数 欧拉定理得 然后指数上中国剩余定理 然后分别lucas定理就好了 注意G==P的时候的特判 /* http://w ...

  8. 数学--数论--中国剩余定理 拓展 HDU 1788

    再次进行中国余数定理 问题描述 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的: 假设m1,m2,-,mk两两互素,则下面同余方程组: x≡a1(mod m1) x≡ a2(mod ...

  9. 51Nod1123 X^A Mod B 数论 中国剩余定理 原根 BSGS

    原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1123.html 题目传送门 - 51Nod1123 题意 $T$ 组数据. 给定 $A,B,C$,求 ...

随机推荐

  1. MSSQL DBcheck

    --1.创建数据库. --create database MyDatabase; --删除数据库 --drop database MyDatabase; ----------------------- ...

  2. Part2-HttpClient官方教程-Chapter4-HTTP 认证

    原文链接地址 HttpClient 提供对由 HTTP 标准规范定义的认证模式的完全支持.HttpClient 的认证框架可以扩展支持非标准的认证模式,比如 NTLM 和 SPNEGO. 4.1 用户 ...

  3. perl6文件操作

    use v6; #perl6中读取文件方法 #:r 只读, :w 只写, :rw 读写, :a 追加 my $fp = open 'filename.txt', :rw; for $fp.^metho ...

  4. CMD命令行下载文件

    远程执行sct的另一种姿势 cscript /b C:\Windows\System32\Printing_Admin_Scripts\zh-CN\pubprn.vbs 127.0.0.1 scrip ...

  5. Vue组件-组件的注册

    注册组件 全局组件 注册组件就是利用Vue.component()方法,先传入一个自定义组件的名字,然后传入这个组件的配置. Vue.component('my-component', { templ ...

  6. vs 2015 插件 supercharger 破解方式

    亲测有效:效果如图 方法如下: 1.打开Supercharger的options; 2.点击Pricing & Registration 3.复制 license  然后再按Paste &am ...

  7. x64dbg

    https://x64dbg.com/ https://github.com/x64dbg/x64dbg https://sourceforge.net/projects/x64dbg/files/s ...

  8. codevs 3287 货车运输 NOIP2013提高组

    题目链接:http://codevs.cn/problem/3287/ 题解: 和bzoj3732一毛一样,只不过是找最大生成树和最小值罢了,具体参见我的bzoj3732的博客 #include< ...

  9. http跟https的区别

    http: Hypertext transform protocol 超文本传输协议 是一个为了传输超媒体文档(比如html)的应用层协议 是为了web的浏览器跟web的server端的交流而设计的, ...

  10. Intersection of Two Linked Lists——经典问题

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...