#include <cstdio>
int main()
{
// freopen("in.txt","r",stdin);
int p,e,i,d,kase=;
while(scanf("%d%d%d%d",&p,&e,&i,&d))
{
if(p==- && e == - && i == - && d== -) break;
const int m1 = ,m2 = ,m3 = ;
const int M1 = m2*m3, M2 = m1*m3, M3 = m1*m2;
const int m11 = ,m22=,m33=;
const int M =m1*m2*m3;
int x = p*m11*M1 + e * m22*M2 + i * m33*M3;
x = (x+M)%M;
if(x-d <= )
printf("Case %d: the next triple peak occurs in %d days.\n",++kase,x-d+M);
else printf("Case %d: the next triple peak occurs in %d days.\n",++kase,x-d);
}
return ;
}

首先了解中国剩余定理,根据扩展欧几里得定理求出M1‘,M2'和M3’的正整数解分别为6,19,2。。。直接算的话M2‘为-9,但是要是正整数解,所以可以用-9+28 = 19.

下面介绍一下中国剩余定理,又叫孙子定理。

若m1,m2,```,mk为两两互质的k个整数,有数x%mi = bi(1<=i<=k).bi已知,求x的解

令M = m1*m2*```*mk,Mi = M/mi```Mi'为满足(Mi'Mi)%mi = 1的正整数解···

x = sum(bi*Mi' * Mi)%M````

验证x是解,用x%mi = bi```,然后证明x是唯一解,假设y也是解,得到x = y%M...所以x就是全部的解了·····

不明白还可以去看下面的链接:

http://www.cnblogs.com/walker01/archive/2010/01/23/1654880.html

POJ 1006 中国剩余定理的更多相关文章

  1. Biorhythms POJ - 1006 中国剩余定理

    定理证明:https://blog.csdn.net/d_x_d/article/details/48466957 https://blog.csdn.net/lyy289065406/article ...

  2. POJ - 2891 中国剩余定理

    \(mod\)存在不互素情况下的CRT #include<iostream> #include<algorithm> #include<cstdio> #inclu ...

  3. POJ 1006-Biorhythms,中国剩余定理,学信安的路过!

                                                       Biorhythms 我竟然1A了, 终于从一天的浑噩中找回点自信了.人生第一次做中国剩余定理的题 ...

  4. POJ1006——中国剩余定理

    题目:http://poj.org/problem?id=1006 中国剩余定理:x= m/mj + bj + aj 讲解:http://www.cnblogs.com/MashiroSky/p/59 ...

  5. POJ 1006:Biorhythms 中国剩余定理

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 121194   Accepted: 38157 Des ...

  6. acm数论之旅--中国剩余定理

    ACM数论之旅9---中国剩余定理(CRT)(壮哉我大中华╰(*°▽°*)╯)   中国剩余定理,又名孙子定理o(*≧▽≦)ツ 能求解什么问题呢? 问题: 一堆物品 3个3个分剩2个 5个5个分剩3个 ...

  7. 《孙子算经》之"物不知数"题:中国剩余定理

    1.<孙子算经>之"物不知数"题 今有物不知其数,三三数之剩二,五五数之剩七,七七数之剩二,问物几何? 2.中国剩余定理 定义: 设 a,b,m 都是整数.  如果 m ...

  8. [TCO 2012 Round 3A Level3] CowsMooing (数论,中国剩余定理,同余方程)

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=12083 这道题还是挺耐想的(至少对我来说是这样).开始时我只会60 ...

  9. poj1006中国剩余定理

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103506   Accepted: 31995 Des ...

随机推荐

  1. Intellij自动下载导入框架包

    忽然发现intellij尽然可以自动导入 框架所需的包,而且可以选择jar包版本,瞬间发现Maven,gradle管理jar包还得写配置文件弱爆了. 以Hibernate为例: 1.ProjectSt ...

  2. 和Java相关的一些好文章(不定期更新)

    1.Java 集合类详解 (包括arraylist,linkedlist,vector,stack,hashmap,hashtable,treemap,collection等). 2.Java 理论与 ...

  3. 机器学习职位 & 面经

    http://www.cnblogs.com/peileyuan/p/4775453.html <浅谈机器学习的职业发展方向> http://blog.sina.com.cn/s/blog ...

  4. iframe 子页面获取父页面的元素并且控制样式

    父页面的代码 <div id="div5" style="position:relative;height:500px;">             ...

  5. text-overflow:ellipsis

    关键字: text-overflow:ellipsis 语法:text-overflow : clip | ellipsis 取值: clip :默认值 .不显示省略标记(...),而是简单的裁切. ...

  6. NGUI Scroll List

    NGUI Scroll List 1.Add GameObject with Script UI Panel(NGUI -> UI -> NGUI Panel) and Script UI ...

  7. SQL Server Profiler教程

    SQL Server Profiler是SQL Server企业版自带的一个sql 语句跟踪和分析工具,功能十分强大.熟练地使用它,对我们分析数据库性能问题很有帮助,比如当数据访问使用EF等ORM框架 ...

  8. hdu 4747 Mex

    http://acm.hdu.edu.cn/showproblem.php?pid=4747 设我们输入的数组为 a[],我们需要从 1 到 n 遍历, 假设遍历到 i 时, 遍历的过程中用b[j]表 ...

  9. sscanf函数

    sscanf函数用法举例 #include <stdio.h> #include <string.h> #define N 512 int main() { char buf[ ...

  10. IE下只读INPUT键入BACKSPACE 后退问题(readonly='true')

    在IE下,如果在readonly的input里面键入backspace键,会触发history.back(), 用以下jquery代码修正之 $("input[readOnly]" ...