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. JavaScript 引擎「V8」发布 8.0 版本,内存占用量大幅下降

    上周,JavaScript 引擎「V8」的开发团队在该项目官方网站上正式宣布推出最新的 8.0 版本.这次更新的重点主要集中在错误修复及性能改善上,正式的版本将在数周后随着谷歌 Chrome 80 稳 ...

  2. vim功能之替换和查找

    vim有着强大的替换和查找功能,若能进行熟练的运用,可以让工作效率得到一个很大程度的提高. 替换 语法:[addr]s/源字符串/目的字符串/[option] [addr]表示检索范围,如: &quo ...

  3. HTML5中改变了哪些东西?

    HTML5 推出的理由 想要把目前web上存在的各种问题一并解决 Web浏览器之间的兼容性很低 文档结构不够明确 Web应用程序的功能受到了限制 HTML5重新定义了浏览器的统一标准 HTML5 与 ...

  4. urllib 库的代替品 requests 的用法

    Requuests 官方的介绍时多么的霸气,之所以那么霸气,是因为 Requestts 相比于 urllib 在使用方面上会让开发者感到更加的人性化.更加简洁.更加舒适,并且国外的一些公司也在使用re ...

  5. 吴裕雄--天生自然ORACLE数据库学习笔记:数据导出与导入

    create directory dump_dir as 'd:\dump'; grant read,write on directory dump_dir to scott; --在cmd下 exp ...

  6. python学习 第一章(说不定会有第零章呢)one day

    ------------恢复内容开始------------ 一.啥是python python是吉尔·范罗苏姆于1989年开发的一个新的脚本解释程序,是ABC语言的一种继承. 二.python的特点 ...

  7. (转)js实现倒计时效果(年月日时分秒)

    原文链接:http://mengqing.org/archives/js-countdown.html 之前做的活动页面很多都用到了倒计时功能,所以整理下下次直接用.(用的是张鑫旭写的一个倒计时,稍作 ...

  8. 【快学springboot】4.接口参数校验

    前言 在开发接口的时候,参数校验是必不可少的.参数的类型,长度等规则,在开发初期都应该由产品经理或者技术负责人等来约定.如果不对入参做校验,很有可能会因为一些不合法的参数而导致系统出现异常. 上一篇文 ...

  9. Victor and String[Bestcoder #52 1004](回文树)

    题目描述 Victor喜欢玩字符串.他认为一个字符串是迷人的,当且仅当字符串是回文的.Victor想玩n次.每次他都会做以下四种操作中的一种.操作1:在字符串的开头添加一个字符 c.操作2:在字符串的 ...

  10. thinkphp5 + vue nginx配置

    thinkphp5 + vue 配置 server { listen ; listen [::]:; # For https listen ssl; listen [::]: ssl; ssl_cer ...