Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier.
Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.

Input

You will be given a number of cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date. The end of input is indicated by a line in which p = e = i = d = -1.

Output

For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in the form:

Case 1: the next triple peak occurs in 1234 days.

Use the plural form ``days'' even if the answer is 1.

Sample Input

0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1

Sample Output

Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days. 思路:同余方程组,此题三个模数互质,直接套即可,注意答案MOD一下21252(题意)
typedef long long LL;
typedef pair<LL, LL> PLL; void ex_gcd(LL a, LL b, LL &x, LL &y, LL &d) {
if(!b) {
d = a, x = , y = ;
} else {
ex_gcd(b, a%b, y, x, d);
y -= x*(a/b);
}
} LL inv(LL a, LL p) { // inv(a) (modp)
LL d, x, y;
ex_gcd(a, p, x, y, d);
return d == ?(x % p + p) % p : -;
} LL China(int *a, int *m, int n) { // x = a[i] (modm[i])
LL M = , ret = ;
for(int i = ; i < n; ++i) M *= m[i];
for(int i = ; i < n; ++i) {
LL w = M / m[i];
ret = (ret + w * inv(w, m[i]) * a[i]) % M;
}
return (ret + M) % M;
} int main() {
int kase = , d, a[], m[], MOD = ;
m[] = , m[] = , m[] = ;
while(scanf("%d%d%d%d", &a[], &a[], &a[], &d)) {
if(a[] == - && a[] == - && a[] == - && d == -) break;
LL ans = ((China(a, m, ) - d) % MOD + MOD) % MOD;
printf("Case %d: the next triple peak occurs in %lld days.\n", ++kase, ans?ans:MOD);
}
return ;
}
												

Day7 - K - Biorhythms POJ - 1006的更多相关文章

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

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

  2. POJ 1006 - Biorhythms (中国剩余定理)

    B - Biorhythms Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Subm ...

  3. POJ 1006 Biorhythms(中国剩余定理)

    题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...

  4. POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)

    POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...

  5. POJ 1006 生理周期(中国剩余定理)

    POJ 1006 生理周期 分析:中国剩余定理(注意结果要大于d即可) 代码: #include<iostream> #include<cstdio> using namesp ...

  6. Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期

    1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...

  7. 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms

    题目链接: http://poj.org/problem?id=1006 http://acm.hdu.edu.cn/showproblem.php?pid=1370 题目大意: (X+d)%23=a ...

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

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

  9. POJ 1006 Biorhythms --中国剩余定理(互质的)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103539   Accepted: 32012 Des ...

随机推荐

  1. win10 免安装版本的MySQL的下载安装和配置

    一.概述 网上找了好多,发现好多不是linux系统的就是与现在新版本有出入,自己做小项目亲手实践了一下,供大家借鉴. MySQL版本:mysql-5.7.17 下载方法: 1.MySQL官方网址htt ...

  2. 装有Ubuntu的硬盘插入到电脑中无法进入

    前言 前段时间,由于自己作死,将BIOS的CPU电压设置解锁,导致BIOS芯片烧坏.在将电脑返厂维修后,我把装有Ubuntu18.04系统的固态硬盘插入到电脑中,但是电脑无法进入grub,采取任何方法 ...

  3. PAT T1002 Business

    背包问题,把任务按截止日期排序,再按背包问题处理~ #include<bits/stdc++.h> using namespace std; ; struct node { int c; ...

  4. SI架构设计与实践

    拆分数据表 水平拆分: 水平拆分 路由算法 pavarotti17 f(pavarotti17) 路由算法——扩容 路由算法——非均匀分布 拆分表的数据访问——SQL转发 si的策略 MySQL集群替 ...

  5. Python数据类型-3 布尔类型

    布尔类型 对于错.0和1.正与反,都是传统意义上的布尔类型. 但在Python语言中,布尔类型只有两个值,True与False.请注意,是英文单词的对与错,并且首字母要大写,不能其它花式变型. 布尔值 ...

  6. node.js的C++入门

    最近的任务是把计划库的API用JavaScript语言调用起来,需要用Node.js的C++扩展,本文简单归总一下node.js addons官方文档https://nodejs.org/api/ad ...

  7. web前端面试第一次[定时器]

    BOM中定时器--计时器 定时器参数两个:(函数,时间(单位ms(1000ms=1s))) 时间设置1s,每过1s执行一次函数 //设置定时器 setInterval(funtion(){ alert ...

  8. BZOJ 4166: 月宫的符卡序列

    如果使用回文树,节点 \(u\) 的回文串和 \(fail_u\) 的回文串中心不一样,因为回文树的 \(fail\) 指针指向的是最长回文后缀,没法快速解决异或和 考虑魔改回文树,用马拉车来解决,扩 ...

  9. 思科 ASA 系列防火墙 官方文档下载指南

    思科 ASA 系列命令参考 思科 ASA 系列命令参考,A 至 H 命令 思科 ASA 系列命令参考, I 至 R 命令 思科 ASA 系列命令参考,S 命令 思科 ASA 系列命令参考, ASASM ...

  10. 十 Restful风格

    1 restful风格化,url上的参数通过{}点符绑定,RequestMapping("item/{id}") 2 点位符参数名与方法参数名不一致时,通过@PathVariabl ...