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. 338.Counting Bits---位运算---《剑指offer》32

    题目链接:https://leetcode.com/problems/counting-bits/description/ 题目大意:求解从0到num的所有数的二进制表示中所有1的个数. 法一:暴力解 ...

  2. <mvc:annotation-driven/>都做了那些事情

    mvc:annotation-driven是一种简写的配置方式,那么mvc:annotation-driven到底做了哪些工作呢?如何替换掉mvc:annotation-driven呢? <mv ...

  3. PHP 利用nginx的X-sendfile控制下载,提高下载效率

    https://blog.csdn.net/qq_34839657/article/details/52812885 https://www.jianshu.com/p/bf5c387830b7 为了 ...

  4. MySQL启动很慢的原因

    我们在启动MySQL的时候,常常会遇到的是, 当执行启动命令后,它会"Start MySQL ....." 一直不停的执行,也不中断,也不成功 这里会出现此现象的原因有以下三条: ...

  5. Getting Started with Django Rest Framework and AngularJS

    转载自:http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html A ReST ...

  6. Hadoop(七)YARN的资源调度

    一.YARN 概述 YARN 是一个资源调度平台,负责为运算程序提供服务器运算资源,相当于一个分布式的操 作系统平台,而 MapReduce 等运算程序则相当于运行于操作系统之上的应用程序 YARN ...

  7. 第 18 章 Django 入门

    当今的网站实际上都是富应用程序(rich application),就像成熟的桌面应用程序一样.Python提供了一组开发Web应用程序的卓越工具.在本章中,我们将学习如何使用Django(http: ...

  8. Scrapy 增加随机请求头 user_agent

    原文: 为什么要增加随机请求头:更好地伪装浏览器,防止被 Ban. 如何在每次请求时,更换不同的 user_agent,Scrapy 使用 Middleware 即可 Spider 中间件 (Midd ...

  9. 【WPF】淡入淡出切换页面

    <NavigationWindow x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsof ...

  10. HDU 6183 Color it

    线段树. 假设只有一种颜色,因为每次询问有一个$x$一定是$1$,那么我可以想办法找出每一个$y$最小的$x$是多少,如果最小的都不符合,那么一定不符合,因为更新变成了单点更新,询问是区间询问最小值, ...