Description

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.
 #include<cstdio>
#include<cstring>
#include<stack>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
int m,n,p,k;
int str[];
int visit[][];
int dis[];
int di[][]={{-,},{,},{,-},{,}};
map<ll,ll>::iterator it;
void exgcd(int a,int b,int &x,int &y)
{
if(b==)
{
x=;
y=;
return ;
}
int x1,y1;
exgcd(b,a%b,x1,y1);
x=y1;
y=x1-a/b*y1;
}
int chinese_pp(int str[],int dis[],int l)
{
int res=,n=,x,y;
for(int i=;i<l;i++)
{
n*=str[i];
}
for(int i=;i<l;i++)
{
int t=n/str[i];
exgcd(t,str[i],x,y);
res=(res+dis[i]*x*t)%n;
}
return (res%n+n)%n;
}
int main()
{
int flag=;
while(cin>>m>>n>>p>>k)
{
flag++;
if(m==-&&n==-&&p==-&&k==-)
break;
str[]=;dis[]=m;
str[]=;dis[]=n;
str[]=;dis[]=p;
int ans=chinese_pp(str,dis,)-k;
if(ans<=)
{
ans+=;
}
printf("Case %d: the next triple peak occurs in %d days.\n",flag,ans);
}
}

Biorhythms(中国剩余定理(模板题))的更多相关文章

  1. Biorhythms(中国剩余定理)

    http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...

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

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

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

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

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

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

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

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

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

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

  7. poj1006 ( hdu1370 ):中国剩余定理裸题

    裸题,没什么好说的 第一个中国剩余定理 写暴力都过了..可见这题有多水 代码: #include<iostream> #include<stdio.h> #include< ...

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

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

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

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

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

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

随机推荐

  1. ajax 提交 注册表单 到MySQL数据库

    今天按照要求,要做一个登陆.注册表单,本来样式做好就行了,本来咱就是干前端的,但让咱自己都没想到的是,不到一个小时竟然都干完了,实在闲的蛋疼,就想到链接数据库玩,遥想当年,毕竟咱也是写过后台的,哪知, ...

  2. 【vs2013】如何在VS的MFC中配置使用GDI+?

    摘自:http://www.cnblogs.com/CSGrandeur/p/3156843.html (已实验,可行) 1.配置GDI+ VS2010自带GDI+,直接使用. (1)首先要添加头文件 ...

  3. 通过ssh限制ip访问

    方法:在/etc/hosts.allow中加入允许的ip,并禁止其他ip sshd:192.168.1.22:allow sshd:ALL:deny 不需要修改/etc/hosts.deny

  4. 【占位】HihoCoder1317 跳舞链

    跳舞链 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho最近遇到一个难题,他需要破解一个棋局. 棋局分成了n行,m列,每行有若干个棋子.小Ho需要从中选择若干行使得 ...

  5. iTunes文件共享

    在Info.plist文件中添加UIFileSharingEnabled键,并将键值设置为YES.将您希望共享的文件放在应用程序的Documents目录.

  6. 最全的Javascript编码规范(推荐)

    1.嵌入规则 Javascript程序应该尽量放在.js的文件中,需要调用的时候在页面中以<script src="filename.js">的形式包含进来.Javas ...

  7. 真正明白c语言二级指针

    指针是C语言的灵魂,我想对于一级指针大家应该都很熟悉,也经常用到:比如说对于字符串的处理,函数参数的“值,结果传递”等,对于二级指针或者多级指针,我想理解起来也是比较容易的,比如二级指针就是指向指针的 ...

  8. Linux环境安装nginx

    安装需要以下工具: yum -y install gcc gcc-c++ autoconf automake 模块依赖: yum -y install zlib zlib-devel openssl ...

  9. 无敌JS关闭当前窗口代码,不弹出确认提示

    echo "<script type='text/javascript'>window.opener=null;window.open('','_self');window.cl ...

  10. dubbox下载编译运行demo

    最近公司要搞微服务改造,拿了一个小项目开刀,找来找去,还是偏向当当的dubbox作为分布式服务框架.这里介绍下怎么一条龙跑起一个demo. 1.下载代码 因为代码放在github上,所以我们直接用Ec ...