E - Biorhythms

Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d
& %I64u

Submit Status

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.

刚接触中国剩余定理,感觉好奇妙啊。x = ( M1*a1*c1 + M2*a2*c2 + M3*a3*c3 。。

)% M ;

M = a1 * a2 *a3.......an ;  要求ai必须互素,不互素的话不能使用中国剩余定理

Mi = M / ai ;    Mi*ai ≡ 1 (mod mi) ;

承认解释不了原因。。。

。。 求大牛解释。

。。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
void gcd(int a,int b,int &d,int &x,int &y)
{
if(b == 0)
{
d = a ;
x = 1 ;
y = 0 ;
}
else
{
gcd(b,a%b,d,y,x);
x = -x ; y = -y ;
y += a/b*x ;
}
return ;
}
int main()
{
int temp = 0 , i , a , b , c , num , d , x , y , M , ans ;
while(scanf("%d %d %d %d", &a, &b, &c, &num)!=EOF)
{
if(a + b + c + num == -4)
break;
a %= 23 ; b %= 28 ; c %= 33 ;
ans = 0 ;
M = 23*28*33 ;
gcd(M/23,23,d,x,y);
x = (x%23+23)%23 ;
ans += M/23*x*a ;
gcd(M/28,28,d,x,y);
x = (x%28+28)%28 ;
ans += M/28*x*b ;
gcd(M/33,33,d,x,y);
x = (x%33+33)%33;
ans += M/33*x*c ;
ans %= M ;
if(ans-num <= 0)
ans += M ;
printf("Case %d: the next triple peak occurs in %d days.\n", ++temp, ans-num);
}
return 0;
}

数论E - Biorhythms(中国剩余定理,一水)的更多相关文章

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

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

  2. acm数论之旅--中国剩余定理

    ACM数论之旅9---中国剩余定理(CRT)(壮哉我大中华╰(*°▽°*)╯)   中国剩余定理,又名孙子定理o(*≧▽≦)ツ 能求解什么问题呢? 问题: 一堆物品 3个3个分剩2个 5个5个分剩3个 ...

  3. POJ 1006:Biorhythms 中国剩余定理

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 121194   Accepted: 38157 Des ...

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

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

  5. poj1006中国剩余定理

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

  6. hihocode 九十七周 中国剩余定理

    题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军 ...

  7. (EX)中国剩余定理

    中国剩余定理 问题引入: 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何?<孙子算经> 就是计算一个数\(x\)满足\(\begin{cases} x≡2(MOD\ 3) ...

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

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

  9. POJ 1006 中国剩余定理

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

随机推荐

  1. Petrozavodsk Summer Training Camp 2017

    Petrozavodsk Summer Training Camp 2017 Problem A. Connectivity 题目描述:有\(n\)个点,现不断地加边.每条边有一种颜色,如果一个点对\ ...

  2. ssh登录时较慢的解决方法

    ssh在登录的时候,通常都会经过DNS的反向解析,过程为: IP --> (反向DNS) --> hostname --> (DNS) --> IP 然后匹配开头申请的和最后得 ...

  3. GPS位置模拟-安卓

    测试定位功能时都需要位置模拟,一般有如下3种方式: a)手机上安装第三方模拟软件:需要Root: b)PC模拟其中运行app并模拟位置:不能在真机上运行,手机兼容性不能测试到: b)在app中让开发增 ...

  4. 解决uc浏览器不支持vw单位的方法

    插入下段代码,使用rem来代替vw <script type="text/javascript"> (function (doc, win) { var docEl = ...

  5. 号外,号外 -几乎所有的binary search和mergesort都有错

    号外,号外 -几乎所有的binary search和mergesort都有错 这是Joshua Bloch(Effective Java的作者)在google blog上发的帖子.在说这个帖子之前,不 ...

  6. 设置或者获取CheckboxList控件的选中值

    1.设置CheckBoxList选中的值 /// <summary> /// 设置CheckBoxList中哪些是选中了的 /// </summary> /// <par ...

  7. 用strtok函数分割字符串

    用strtok函数分割字符串 需要在loadrunner里面获得“15”(下面红色高亮的部分),并做成关联参数. //Body response 内容: <BODY><; PRE&g ...

  8. Java8所有的包介绍(由英文文档翻译而来)

    转载: Java8所有的包介绍(由英文文档翻译而来)

  9. ftp缓存信息

    using System.Collections.Generic; using NewTempo.Ftp; using System.IO; using NshowAdClient.NshowAdSe ...

  10. 【ASP.NET MVC】Scripts目录

    很多时候我们经常在用的东西我们可能不一定真正的了解,因为我们可能已经会用了,便不再对其进行探索,下面我们看一下在ASP.NET MVC3项目下的Scripts目录下的文件: Jquery核心库我们就不 ...