数论E - Biorhythms(中国剩余定理,一水)

时间:2022-09-21 10:05:07
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. &lbrack;TCO 2012 Round 3A Level3&rsqb; 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. &lpar;EX&rpar;中国剩余定理

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

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

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

  9. POJ 1006 中国剩余定理

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

随机推荐

  1. Sublime text 3 快捷键的使用

    快捷键的便捷使用: ctr+shift+n:打开新的sublime text ctr+shift+w:关闭sublime text ctr+o:打开 某个文件 ctrl+n:新建一个文本 ctrl+w ...

  2. 在页面关闭或者刷新的时候触发 onbeforeunload

    该实例演示了如何使用 HTML DOM 向 body 元素添加 "onbeforeunload" 事件. 关闭当前窗口,按下 F5 或点击以下链接触发 onbeforeunload ...

  3. 网络编程1--毕向东java基础教程视频学习笔记

    目录: 01 网络编程概述1 02 网络编程概述2 03网络编程 网络模型 04网络编程 IP地址 05网络编程 TCP和UDP 06网络编程 Socket 07网络编程 UDP发送端 01 网络编程 ...

  4. Ext TabPanel items高度宽度自适应

    写Ext的时候经常会遇到一些莫名其妙,令人感到非常神奇的问题,甚至都没办法用语言去描述它,搞的人想请教一下百度或Google都不知道该去怎么问,简直能够令人发疯.先来看张截图吧. 有没有注意到里面的G ...

  5. Oracle中如何使用REGEXP&lowbar;SUBSTR函数

    REGEXP_SUBSTR函数格式如下: function REGEXP_SUBSTR(String, pattern, position, occurrence, modifier) __srcst ...

  6. 使用 preferredStatusBarStyle 设置状态栏颜色

    iOS9之前,在plist文件中 插入一个新的key,名字为View controller-based status bar appearance,并将其值设置为NO. 然后敲入代码: [UIAppl ...

  7. Apache 使用密码文件验证用户

    使用文本文件作为密码文件 创建密码文件 需要使用htpasswd.exe文件来创建用户密码文件 语法: htpasswd -c '文件完整路径' 用户名 向一个用户密码文件中添加一个新用户 语法: h ...

  8. eclipse(Version&colon; Neon Release &lpar;4&period;6&period;0&rpar;)安装hibernate tools

    这里需要说明的是,hibernate tools是jboss推出的. eclipse——>Eclipse Marketplace... 输入jboss-tools进行搜索 选择jboss too ...

  9. SQL 2008 数据库迁移

    1,改动迁移路径 USE master GO ALTER DATABASE 数据库名  --主数据 MODIFY FILE(NAME='数据库名', FILENAME='F:\DataBase\数据库 ...

  10. HTML模块化:使用HTML5 Boilerplate模板

    HTML5 Boilerplate 是一个由 Paul Irish(Google Chrome 开发人员.jQuery 项目成员.Modernizr 作者.yayQuery 播客主持人)主导的“前端开 ...