Biorhythms
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 103506   Accepted: 31995

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 <iostream>
#include <math.h>
using namespace std;
#define ll long long int
ll funa(ll a,ll b)
{
if(b==) return a;
return funa(b,a%b);
}
void fun(ll a,ll b,ll &x,ll &y)
{
if(b==)
{
x=;
y=;
return ;
}
fun(b,a%b,x,y);
ll t=x;
x=y;
y=t-(ll)(a/b)*y;
}
int main()
{
ll a[],r[],k[],d[];
int i;
ll n;
ll t=;
while(){
a[]=;a[]=;a[]=;
ll p=**;
for(i=;i<;i++)
{
cin>>r[i];
k[i]=p/a[i];
}
cin>>n;
if(r[]==-&&r[]==-&&r[]==-&&n==-)
break;
ll sum=;
for(i=;i<;i++)
{
ll x,y;
fun(k[i],a[i],x,y);
//x=(x%a[i]+a[i])%a[i];
d[i]=x*k[i]*r[i];
//cout<<d[i]<<endl;
sum+=d[i];
sum%=p;
}
if(sum<=n)
sum+=p;
cout<<"Case "<<t++<<": the next triple peak occurs in "<<sum-n<<" days."<<endl; }
}

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

  1. POJ1006——中国剩余定理

    题目:http://poj.org/problem?id=1006 中国剩余定理:x= m/mj + bj + aj 讲解:http://www.cnblogs.com/MashiroSky/p/59 ...

  2. POJ1006 Biorhythms —— 中国剩余定理

    题目链接:https://vjudge.net/problem/POJ-1006 Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total ...

  3. 《孙子算经》之"物不知数"题:中国剩余定理

    1.<孙子算经>之"物不知数"题 今有物不知其数,三三数之剩二,五五数之剩七,七七数之剩二,问物几何? 2.中国剩余定理 定义: 设 a,b,m 都是整数.  如果 m ...

  4. POJ 1006 中国剩余定理

    #include <cstdio> int main() { // freopen("in.txt","r",stdin); ; while(sca ...

  5. [TCO 2012 Round 3A Level3] CowsMooing (数论,中国剩余定理,同余方程)

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=12083 这道题还是挺耐想的(至少对我来说是这样).开始时我只会60 ...

  6. (伪)再扩展中国剩余定理(洛谷P4774 [NOI2018]屠龙勇士)(中国剩余定理,扩展欧几里德,multiset)

    前言 我们熟知的中国剩余定理,在使用条件上其实是很苛刻的,要求模线性方程组\(x\equiv c(\mod m)\)的模数两两互质. 于是就有了扩展中国剩余定理,其实现方法大概是通过扩展欧几里德把两个 ...

  7. 洛谷P2480 [SDOI2010]古代猪文(费马小定理,卢卡斯定理,中国剩余定理,线性筛)

    洛谷题目传送门 蒟蒻惊叹于一道小小的数论题竟能涉及这么多知识点!不过,掌握了这些知识点,拿下这道题也并非难事. 题意一行就能写下来: 给定\(N,G\),求\(G^{\sum \limits _{d| ...

  8. 洛谷P3868 [TJOI2009]猜数字(中国剩余定理,扩展欧几里德)

    洛谷题目传送门 90分WA第二个点的看过来! 简要介绍一下中国剩余定理 中国剩余定理,就是用来求解这样的问题: 假定以下出现数都是自然数,对于一个线性同余方程组(其中\(\forall i,j\in[ ...

  9. POJ2891 Strange Way to Express Integers 扩展欧几里德 中国剩余定理

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ2891 题意概括 给出k个同余方程组:x mod ai = ri.求x的最小正值.如果不存在这样的x, ...

随机推荐

  1. Vue.js入门指南(一)

      前  言 JRedu 之前用过一段时间的AnglarJS 1.X,在低版本的AngularJS中,脏值检查在变量增多的情况下会影响程序的响应速度.后期的2.X和更高版本在脏值检查等问题上做了优化, ...

  2. Selenium 定位网页元素

    第一 定位元素辅助工具 IE中在元素上右击 ->  “检查元素”,或按F12键打开开发者工具: Chrome中在元素上右击 -> “审查元素”,或按F12键打开开发者工具: Firefox ...

  3. websocket实现简单聊天程序

    程序的流程图: 主要代码: 服务端 app.js 先加载所需要的通信模块: var express = require('express'); var app = express(); var htt ...

  4. 花生壳DDNS为何不支持LetsEncrypt申请

    Inspired by Let's Encrypt Community , thx to sahsanu, jsha, and orzorc. 开端 Lets Encrypt 是一款免费的网站 SSL ...

  5. Day-12: 进程和线程

    进程和线程 在操作系统看来,一个任务就是一个进程,而一个进程内部如果要做多个任务就是有多个线程.一个进程至少有一个线程. 真正的并行执行任务是由多个CUP分别执行任务,实际中是由,操作系统轮流让各个任 ...

  6. JS中的事件&对象

    一.JS中的事件 (一)JS中的事件分类 1.鼠标事件 click/dblclick/onmouseover/onmouseout 2.HTML事件 onload/onscroll/onsubmit/ ...

  7. 团队作业8——Beta版本冲刺计划及安排

    团队作业8--Beta版本冲刺计划及安排 经过紧张的Alpha阶段,很多组已经从完全不熟悉语言和环境,到现在能够实现初步的功能.下一阶段即将加快编码进度,完成系统功能.强化软件工程的体会. 凡事预则立 ...

  8. 201521123097《Java程序设计》第六周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 1.clone方法 1.1 Object对 ...

  9. 201521123096《Java程序设计》第四周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 继承能够动态绑定,运行时能够自动的选择调用方法,十分方便. 2. 书面作业 (1)注释的应用 ...

  10. 201521123012 《Java程序设计》第三周学习总结

    一.本章学习总结 1.面对对象:(1)类 <1>属性 [1]外部类 [2]内部类 <2>方法 [1]j静态 [2]非静态 (2)对象 <1>创建对象 <2&g ...