ACM: 一道简单数论题 (重要的是建…
来源:互联网 发布:在淘宝上如何开店 编辑:程序博客网 时间:2024/05/14 00:34
Description
Some people believe that there are three cycles in a person'slife that start the day he or she is born. These three cycles arethe physical, emotional, and intellectual cycles, and they haveperiods of lengths 23, 28, and 33 days, respectively. There is onepeak in each period of a cycle. At the peak of a cycle, a personperforms 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 beeasier.
Since the three cycles have different periods, the peaks of thethree cycles generally occur at different times. We would like todetermine when a triple peak occurs (the peaks of all three cyclesoccur in the same day) for any person. For each cycle, you will begiven the number of days from the beginning of the current year atwhich one of its peaks (not necessarily the first) occurs. You willalso be given a date expressed as the number of days from thebeginning of the current year. You task is to determine the numberof days from the given date to the next triple peak. The given dateis not counted. For example, if the given date is 10 and the nexttriple peak occurs on day 12, the answer is 2, not 3. If a triplepeak occurs on the given date, you should give the number of daysto the next occurrence of a triple peak.
Input
You will be given a number of cases. The input for each caseconsists 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 currentyear at which the physical, emotional, and intellectual cyclespeak, respectively. The value d is the given date and may besmaller than any of p, e, or i. All values are non-negative and atmost 365, and you may assume that a triple peak will occur within21252 days of the given date. The end of input is indicated by aline in which p = e = i = d = -1.
Output
For each test case, print the case number followed by a messageindicating the number of days to the next triple peak, in theform:
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 728
3 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.
则N=k1*d2*d3*R1+k2*d1*d3*R2+k3*d1*d2*R3±d1*d2*d3*P
其中
P为任意非负整数
k1是满足k1*d2*d3≡1(mod d1)的最小正整数
k2是满足k2*d1*d3≡1(mod d2)的最小正整数
k3是满足k3*d1*d2≡1(mod d3)的最小正整数
C语言:Ki 求解:
for(i = 1; ; ++i)
{
}
AC的代码:
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
//
}
- ACM: 一道简单数论题 (重要的是建…
- ACM: 一道数论题 poj1730 (做了好…
- ACM: n!末尾0的个数 数论题 poj 14…
- ACM: polay定理 数论题 poj 1286 …
- ACM : 数论题 poj1061 (扩展欧几…
- ACM: 矩阵建模 数论题 poj 3735 (…
- ACM: 二分法 数论题 poj 1905
- ACM: polya定理+hash 数论题 poj 3…
- ACM: 矩阵快速幂运算 数论题 poj 3…
- ACM: 简单最小生成树 图论题 poj 1…
- ACM: 数论题 toj 1721
- ACM: 图论题 poj 1789 (一次AC的水…
- ACM: 图论题 poj 2253 (poj上的dou…
- ACM: 图论题 poj3259 bellman_ford…
- ACM: 图论题 poj 3…
- ACM: 图论题 poj 1…
- ACM: 图论题 poj 1…
- ACM: 数论题 toj3343 同 poj 1061
- ACM: 一题大数求mod poj2635 (…
- ACM: 一道数论题 poj1730 (做了好…
- ACM: 一道水题 poj1723
- ACM : 数论题 poj1061 (扩展欧几…
- ACM : 一道基础数学题目POJ 1423 …
- ACM: 一道简单数论题 (重要的是建…
- Android matrix camera处理图片绕X轴Y轴翻转(类似3D效果)
- ACM: 图论题 poj3259 bellman_ford…
- <从PAXOS到ZOOKEEPER分布式一致性原理与实践>读书笔记-zookeeper全局唯一id生成
- ACM: 图论题poj 1860 (没心情复习…
- ACM: 图论基础题 poj2387 裸露的di…
- ACM: poj 第50题 一题递推数论题 …
- ACM: 又是一题二分法题 poj 3122…
- ACM: 一题二分搜索题. poj3258 …