描述

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.

输入

You will be given at most 1000000 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

输出

For each test case, print the number of days to the next triple peak, in the form:

样例输入

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

样例输出

21252
21152
19575
16994
8910
10789

学信安的我表示学过中国剩余定理但是做题还是不会…..

还要看别人博客才知道要用到中国剩余定理,妈卖批!!!

中国剩余定理:

基本公式为:x+d=M1*y1*p+M2*y2*e+M3*y3*i

x+d=p(mod 23);

x+d=e(mod 23);

x+d=i(mod 23);

M=23*28*33=21252,M1=924,M2=759,M3=644;

924y1=1(mod 23);

644y3=1mod 33);

(这个是由Mk*yk=1(mod mk 可以知道 至于为 什么 我还是从一 篇别人的博客里知道的 至于原因 也没有写)

可以得出来:y1=6,y2=19,y3=2;

进而:x+d=(5544*p+14421*e+1288*i)%21252;

注意:x不能是负数,所以修改为x=(5544*p+14421*e+1288*i-d+21252)%21252;

#include<cstdio>
using namespace std;
int main()
{
int p, e, i, d, icase = 0, x;
while (scanf("%d%d%d%d", &p, &e, &i, &d), ~p)
{
x = (5544 * p + 14421 * e + 1288 * i - d + 21252) % 21252;
if (x == 0)
x = 21252;
printf("%d\n",x);
}
return 0;
}

nyoj 151 Biorhythms的更多相关文章

  1. NYOJ 8 一种排序(comparator排序)

    一种排序 时间限制: 3000 ms  |  内存限制: 65535 KB 难度: 3   描述 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编号.长.宽都 ...

  2. NYOJ 1007

    在博客NYOJ 998 中已经写过计算欧拉函数的三种方法,这里不再赘述. 本题也是对欧拉函数的应用的考查,不过考查了另外一个数论基本定理:如何用欧拉函数求小于n且与n互质所有的正整数的和. 记eule ...

  3. NYOJ 998

    这道题是欧拉函数的使用,这里简要介绍下欧拉函数. 欧拉函数定义为:对于正整数n,欧拉函数是指不超过n且与n互质的正整数的个数. 欧拉函数的性质:1.设n = p1a1p2a2p3a3p4a4...pk ...

  4. poj1006 / hdu1370 Biorhythms (中国剩余定理)

    Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p;   (n+d)%28=e;   (n+d)%33=i ,求n .        (题在文末) 知识点:中国剩余定理 ...

  5. NYOJ 333

    http://www.cppblog.com/RyanWang/archive/2009/07/19/90512.aspx?opt=admin 欧拉函数 E(x)表示比x小的且与x互质的正整数的个数. ...

  6. NYOJ 99单词拼接(有向图的欧拉(回)路)

    /* NYOJ 99单词拼接: 思路:欧拉回路或者欧拉路的搜索! 注意:是有向图的!不要当成无向图,否则在在搜索之前的判断中因为判断有无导致不必要的搜索,以致TLE! 有向图的欧拉路:abs(In[i ...

  7. nyoj 10 skiing 搜索+动归

    整整两天了,都打不开网页,是不是我提交的次数太多了? nyoj 10: #include<stdio.h> #include<string.h> ][],b[][]; int ...

  8. NYOJ题目1080年龄排序

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtMAAAJVCAIAAACTf+6jAAAgAElEQVR4nO3dO1Lj3NbG8W8Szj0QYg ...

  9. poj 1006:Biorhythms(水题,经典题,中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 Des ...

随机推荐

  1. ThinkSnS v4后台任意文件下载漏洞

    漏洞文件: /apps/admin/Lib/Action/UpgradeAction.class.php 主要问题还是出现在了180行直接将远程获取到的图片直接保存. 文中可见并没有做任何的对$dow ...

  2. metasploit后门维持技术

    在meterpreter中执行:run metsvc -A 如此以后便会自动在服务器当中多生成一个meterpreter的服务,并且是开机自动启动.所以二次如果要利用直接: use exploit/m ...

  3. Jmeter跨线程组传递变量

    请求API需要授权令牌,但是授权令牌只需要获取一次,即可调用服务器上其他业务接口. 所以我想要把授权操作放在单独的一个线程,业务流放在其他线程. 这就需要我把从授权线程获取的令牌传入业务流线程. 解决 ...

  4. Iptables基础整理

    Iptables基础框架

  5. div左右自适应高度一致

    <div style="width:300px;"> <div id="Left" style="float:left;" ...

  6. WdatePicker做出onchange效果

    WdatePicker({onpicking: function (dp) {if (dp.cal.getDateStr() != dp.cal.getNewDateStr()) { Func(dp. ...

  7. tomcat修改内存

    windows: 修改bin/catalina.bat, 第一行添加 set JAVA_OPTS=-Xms256m -Xmx512m linux: 修改bin/catalina.sh 第一行添加 JA ...

  8. linux命令(41):watch命令

    watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...

  9. for in 对象时,属性为非负整数的情况

    在我做一个需求的时候 for in 一个对象,对象的属性都是数字 但是我想给这个对象加一个默认的属性跟值 原对象是{5446:"广州市"}.....类似于下去 然后我想给我页面展示 ...

  10. [转载] login shell和non-login shell

    原文地址:这里. 在linux中我们知道当你输入一条命令的时候,命令的查找是根据环境变量PATH来查找的,如果想知道一个命令的源文件存放在什么地方可以用which或whereis指令.那么PATH变量 ...