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. 散列表(拉链法与线性探测法)Java实现

    package practice; import java.security.Principal; import java.util.Scanner; import edu.princeton.cs. ...

  2. Apache2 httpd.conf 配置详解(一)

    常用配置指令说明 ServerRoot:服务器的基础目录,一般来说它将包含conf/和logs/子目录,其它配置文件的相对路径即基于此目录.默认为安装目录,不需更改. 语法:ServerRoot di ...

  3. Servlet和JSP生命周期概述

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt374 Servlet生命周期分为三个阶段: 1,初始化阶段  调用init( ...

  4. CSS背景效果

    前面的话 本文将详细介绍CSS背景效果 条纹背景 [双条纹背景] background:linear-gradient(#fb3 50%, #58a 50%); background-size: 10 ...

  5. 阿里云Prismplayer-Web播放器的使用

    Prismplayer是一套在线视频播放技术方案,同时支持Flash和Html5两种播放技术,可对播放器进行功能配置和皮肤定制.其在线使用文档地址为:https://help.aliyun.com/d ...

  6. 当今游戏大作share的特性大盘点

    极品游戏制作时的考虑要素大盘点 不知不觉入坑Steam已近4年,虽然说Steam的毒性让很多人走向一条不归路,但是想我这样即使"中毒"还是很快乐很感恩的.那么本期文章就谈谈我对其中 ...

  7. 团队作业8——第二次项目冲刺(Beta阶段)--5.26 sixth day

    团队作业8--第二次项目冲刺(Beta阶段)--5.26 sixth day Day six: 会议照片 项目进展 Beta冲刺的第四天,以下是今天具体任务安排: 队员 昨天已完成的任务 今日计划完成 ...

  8. 201521123091 《Java程序设计》第14周学习总结

    Java 第十四周总结 第十四周的作业. 目录 1.本章学习总结 2.Java Q&A 3.码云上代码提交记录及PTA实验总结 4.课后阅读 1.本章学习总结 以你喜欢的方式(思维导图或其他) ...

  9. 201521123008《Java程序设计》第1周学习总结

    本周学习总结 了解了JAVA:jdk:jre:jvm等 C语音与JAVA的部分区别: C语言全面向过程,java面向对象: C语言的代码不能跨平台,java的代码可以跨平台: C语言有指针,java没 ...

  10. 201521123081《java程序设计》 第13周学习总结

    本次作业参考文件 正则表达式参考资料 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 参考资料:XMind 2. 书面作业 Q1. 网络基础 1.1 比较 ...