#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm> using namespace std;
typedef long long ll;
const int maxn = ;
ll exgcd(ll a, ll b, ll &x, ll &y)
{
if (b == )
{
x = ;
y = ;
return a;
}
ll r = exgcd(b, a % b, x, y);
ll t = x;
x = y;
y = t - a / b * y;
return r;
}
ll china_remainder(int a[], int w[], int n)//w存放除数,a存放余数
{
ll M = , ans = , x, y;
for (int i = ; i < n; i++)
M *= w[i];
for (int i = ; i < n; i++)
{
ll m = M / w[i];
exgcd(m, w[i], x, y);
ans = (ans + x * m * a[i]) % M;
}
return (ans % M + M) % M;
}
int main()
{
int T, m, a[maxn], w[maxn];
w[] = ; w[] = ; w[] = ;
ll n = ;
int p, e, i, d, kase = ;
while (~scanf("%d %d %d %d", &p, &e, &i, &d))
{
if (p == - && e == - && i == - && d == -)
break;
a[] = p;
a[] = e;
a[] = i;
ll ans = china_remainder(a, w, n);
ans -= d;
int mod = w[] * w[] * w[];
ans = (ans % mod + mod) % mod;
if (ans == )
ans = mod;
printf("Case %d: the next triple peak occurs in %lld days.\n", ++kase, ans); }
return ;
}

中国剩余定理模板poj1006的更多相关文章

  1. 中国剩余定理模板 51nod 1079

    题目链接:传送门 推荐博客:https://www.cnblogs.com/freinds/p/6388992.html (证明很好,代码有误). 1079 中国剩余定理  基准时间限制:1 秒 空间 ...

  2. Monkey Tradition---LightOj1319(中国剩余定理模板)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1319 题意:有 n 个猴子,n 棵树,树的高度为 L ,每个猴子刚开始的时候都在树的底 ...

  3. poj 1006中国剩余定理模板

    中国剩余定理(CRT)的表述如下 设正整数两两互素,则同余方程组 有整数解.并且在模下的解是唯一的,解为 其中,而为模的逆元. 模板: int crt(int a[],int m[],int n) { ...

  4. poj 1006 Biorhythms (中国剩余定理模板)

    http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...

  5. 【学习笔记-中国剩余定理】POJ1006 Biorhythms

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 139500   Accepted: 44772 Des ...

  6. 51nod 1079 中国剩余定理模板

    中国剩余定理就是同余方程组除数为质数的特殊情况 我直接用同余方程组解了. 记得exgcd后x要更新 还有先更新b1再更新m1,顺序不能错!!(不然会影响到b1的更新) #include<cstd ...

  7. [洛谷P1495] 曹冲养猪 (中国剩余定理模板)

    中国剩余定理(朴素的)用来解线性同余方程组: x≡a[1] (mod m[1]) x≡a[2] (mod m[2]) ...... x≡a[n] (mod m[n]) 定义ms=m[1]*m[2]*. ...

  8. 【数论】【中国剩余定理】poj1006 生理周期

    CRT用于求解一元线性同余方程组(模数互质),实际上模数不互质我们也可以解决,在之前的某篇文章里提过.如下 http://www.cnblogs.com/autsky-jadek/p/6596010. ...

  9. 中国剩余定理模板&俄罗斯乘法

    void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b){d=a;x=1LL;y=0LL;} else {ex_gcd(b,a%b,d, ...

随机推荐

  1. 枚举宏(Adopting Modern Objective-C)

    使用NS_ENUM 和 NS_OPTIONS宏定义枚举.Adopting Modern Objective-C 使用NS_ENUM宏定义一组互斥的枚举值: typedef NS_ENUM(NSInte ...

  2. 黑马程序员—C语言的特点和关键字

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- C语言的简介 一. C语言具有下列特点: C语言既具有低级语言直接操纵硬件的特点,又具有高级语言 ...

  3. 为iOS 7而开发 并支持iOS 6

    除了写这本“Developing an iOS 7 Edge”书之外,我还针对iOS 7更新了app,所以我想我应该和大家分享一下我的收获.如果你正在面向iOS 7系统更新应用,同时你的应用还支持iO ...

  4. ssh远程登录Ubuntu报错:Permission denied, please try again.

    ssh到server上的时候密码是对的但是报如下信息:# ssh 172.16.81.221root@172.16.81.221's password:Permission denied, pleas ...

  5. Adobe Acrobat XI Pro 两种破解方式 Keygen秘钥 license替换 亲测有效

    大家平时看paper比较多的话想必都是用Adobe Acrobat而非Adobe Reader吧,其功能全面之处就不啰嗦了,下面给大家分享下Adobe Acrobat XI Pro的两种破解方式(两种 ...

  6. (摘录)data guard switchover切换异常

    查看DG数据库备份库发现,switchover_status为SWITCHOVER LATENT SQL> select OPEN_MODE,PROTECTION_MODE,PROTECTION ...

  7. K Smallest Sums

    uva11997:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...

  8. XSHELL和XFTP,亲兄弟啊。

    XSHELL在LINUX和WINDOWS之间传输文件时不力啊.又对FTP不灵活的时候,XFTP就可以出场了. 只要登陆进XSHELL就可以操作了.并且XFTP客户端和命令行可以灵活配置选择. 然后,玩 ...

  9. Hibernate如何一个类映射两个表

    一个User类有username,password属性,还有 otherInformation等其他属性,username和password映射到一个表,otherInformation等其他属性映射 ...

  10. BZOJ 1093 [ZJOI2007]最大半连通子图

    1093: [ZJOI2007]最大半连通子图 Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1986  Solved: 802[Submit][St ...