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. 端口打开和关闭do while

    ;Author : Bing Song ;// ;Usage: modify “logfile" according to actual drictory getdir logdir #获取 ...

  2. 八 Spring的IOC的XML和注解的区别及其整合开发

    xml和注解的区别 xml和注解整合开发 注解:取消扫描配置开启注解配置 扫描:<context:component-scan base-package="" />  ...

  3. 碰到的问题——建设基于TensorFlow的深度学习环境

    1.解决jupyter notebook问题:socket.error: [Errno 99] Cannot assign requested address 首先要生成一个jupyter的配置文件: ...

  4. CentOS初始化脚本(未完)

    #!/bin/bash release=`` .shutdown selinux [ -e "/etc/selinux/config" ] && sed -i 's ...

  5. eclipse导入项目上面有个红叉X

    问题: 今天突然想到一个以前做过的项目,想导入到新环境中,发现不管咱整都一个红叉X, 我记得以前好像碰到过类似的问题,当时三秒搞定,谁知道时间一长,三分钟没有搞定. 还是记录下: 一般导入项目出错,肯 ...

  6. Android studio For Mac 安装

    简介: Google在2013的I/O开发者大会上正式对外宣布Android Studio将作为Android开发的主要IDE,它是基于IntelliJ IDEA打造的一款专门开发Android的神器 ...

  7. Linux centosVMware运行告警系统、分发系统-expect讲解、自动远程登录后,执行命令并退出、expect脚本传递参数、expect脚本同步文件、指定host和要同步的文件、shell项目-分发系统-构建文件分发系统、分发系统-命令批量执行

    一运行告警系统 创建一个任务计划crontab -e 每一分钟都执行一次 调试时把主脚本里边log先注释掉 再次执行 没有发现502文件说明执行成功了,每日有错误,本机IP 负载不高 二.分发系统-e ...

  8. 表格中td限宽溢出以省略号代替

    table.ms-listviewtable { table-layout:fixed; width: 100%; } table.ms-listviewtable td[role="gri ...

  9. 如何用python写个人专属群聊提醒小助手?

    前言 大家还记得教会父母玩微信是什么时候吗?父母学会后,我们的生活就发生了「质」的变化,父母也许会吐槽你的微信头像不好,要你换一个头像. 最近 pk哥 又被母后大人吐槽了,原因是亲戚微信群里某个亲戚生 ...

  10. 搜索控制器UISearchController的使用

    说明:本文主要是将系统UISearchController控件声明文件中的属性.方法.代理等介绍下,后续再联合[搜索栏UISearchBar]这篇文章一起更新更实用的信息. 1.初始化 // 如果设置 ...