数论E - Biorhythms(中国剩余定理,一水)
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d
& %I64u
Description
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
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
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(中国剩余定理,一水)的更多相关文章
- POJ1006 Biorhythms —— 中国剩余定理
题目链接:https://vjudge.net/problem/POJ-1006 Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total ...
- acm数论之旅--中国剩余定理
ACM数论之旅9---中国剩余定理(CRT)(壮哉我大中华╰(*°▽°*)╯) 中国剩余定理,又名孙子定理o(*≧▽≦)ツ 能求解什么问题呢? 问题: 一堆物品 3个3个分剩2个 5个5个分剩3个 ...
- POJ 1006:Biorhythms 中国剩余定理
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 121194 Accepted: 38157 Des ...
- [TCO 2012 Round 3A Level3] CowsMooing (数论,中国剩余定理,同余方程)
题目:http://community.topcoder.com/stat?c=problem_statement&pm=12083 这道题还是挺耐想的(至少对我来说是这样).开始时我只会60 ...
- poj1006中国剩余定理
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103506 Accepted: 31995 Des ...
- hihocode 九十七周 中国剩余定理
题目1 : 数论六·模线性方程组 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho:今天我听到一个挺有意思的故事! 小Hi:什么故事啊? 小Ho:说秦末,刘邦的将军 ...
- (EX)中国剩余定理
中国剩余定理 问题引入: 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何?<孙子算经> 就是计算一个数\(x\)满足\(\begin{cases} x≡2(MOD\ 3) ...
- 《孙子算经》之"物不知数"题:中国剩余定理
1.<孙子算经>之"物不知数"题 今有物不知其数,三三数之剩二,五五数之剩七,七七数之剩二,问物几何? 2.中国剩余定理 定义: 设 a,b,m 都是整数. 如果 m ...
- POJ 1006 中国剩余定理
#include <cstdio> int main() { // freopen("in.txt","r",stdin); ; while(sca ...
随机推荐
- Petrozavodsk Summer Training Camp 2017
Petrozavodsk Summer Training Camp 2017 Problem A. Connectivity 题目描述:有\(n\)个点,现不断地加边.每条边有一种颜色,如果一个点对\ ...
- Python 中的闭包与装饰器
闭包(closure)是函数式编程的重要的语法结构.闭包也是一种组织代码的结构,它同样提高了代码的可重复使用性. 如果在一个内嵌函数里,对在外部函数内(但不是在全局作用域)的变量进行引用,那么内嵌函数 ...
- Windows: 在系统启动时运行程序、定时计划任务、定时关机
lesca今天介绍一些让系统在启动时,而非登录时,加载用户自定义的应用程序或脚本的方法,推荐度从前到后依次递减. 1. Windows任务计划(task scheduler) 用户可以按以下步骤进行操 ...
- NTP详解-转
网管实战:Linux时间服务器配置 [IT168 专稿]目前计算机网络中各主机和服务器等网络设备的时间基本处于无序的状态.随着计算机网络应用的不断涌现,计算机的时间同步问题成为愈来愈重要的事情.以Un ...
- hdu 5918(强行水过去..正解KMP)
Sequence I Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- Copy List with Random Pointer——技巧
A linked list is given such that each node contains an additional random pointer which could point t ...
- 洛谷P1094纪念品分组 题解
题目传送门 首先的思路就是贪心.先将所有的纪念品按照价格从低到高进行排序.在分别从左到右.从右到左合并纪念品.如果两端纪念品价格超过了上上限,那么就将较大的那一个纪念品独自放入.否则将两个纪念品一起放 ...
- Python/Anaconda多版本共存的解决方案
博客中的文章均为 meelo 原创,请务必以链接形式注明 本文地址 虽然Python2大势已去,众多项目都已经支持Python3,但总有一些教程和项目只支持Python2.通常情况是计算机里既装着Py ...
- linux的文件隐藏属性 chattr lsattr
<鸟哥的Linux私房菜 基础学习篇(第三版)> 7.4.2 读书笔记 显然,这里要说的并不是rwx那9个权限,而是要聊chattr和lsattr这两个命令.这两个命令在只能在Ext2/E ...
- shell动画
在印象中,好像终端就是黑白界面,加扁平输出.是不是很乏味?其实现在 Linux/Unix 系统中带的终端模拟器是支持动画和彩色输出的.下面,一起来看看字符界面下的动画魅力! 1 定点输出 1.1 回车 ...