数论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 ...
随机推荐
- WebAPI使用Swagger生成接口文档
开发工具:VS2017 版本15.7.1 新建项目,选择空模板,下面只勾选WebAPI 配置Web.config <system.webServer> 节点改为 <system.we ...
- (六)Spring4 整合Hibernate4,Struts2
第一节:S2SH 整合所需Jar 包 Struts2.3.16,Spring4.0.6,Hibernate4.3.5 整合所需jar 包: Struts2.3.16 jar 包 Spring4.0.6 ...
- 洛谷 P2369 EXCEEDED WARNING A 题解
题目传送门 直接用sort排序最后输出即可.但是数组要使用short int 类型.否则会超内存. #include<bits/stdc++.h> using namespace std; ...
- JavaScript中的数据类型总结
Javascript是一种弱类型语言,没有明确的类型分类:网上分类的方式比较多,个人感觉不比去特别的追究细分是什么什么类型,若是能够明确的分出类型的话,javascript就不是弱类型语言,又由于大家 ...
- IEEEXtreme 10.0 - Inti Sets
这是 meelo 原创的 IEEEXtreme极限编程大赛题解 Xtreme 10.0 - Inti Sets 题目来源 第10届IEEE极限编程大赛 https://www.hackerrank.c ...
- 【PAT】1002. A+B for Polynomials (25)
1002. A+B for Polynomials (25) This time, you are supposed to find A+B where A and B are two polynom ...
- 用strtok函数分割字符串
用strtok函数分割字符串 需要在loadrunner里面获得“15”(下面红色高亮的部分),并做成关联参数. //Body response 内容: <BODY><; PRE&g ...
- 【SQL SERVER】T-SQL 字符串前加 N 是什么意思
比如 select @status = N'stopped' 那么其中的字符串 stopped 前面为什么要加 N 呢?而且我们发现有些地方加 N 与否都没有影响,有些地方又必须加 N. N 在这里表 ...
- linux下php pcntl_fork模拟多线程
开始用php写后台服务一段时间了.也是在这样的驱动下,不断的学习php语法,体验这一原来一直以为神秘且敬而远之的神奇语言的魅力.最初看php多线程的资料是为了提高程序的处理能力,充分发挥linux多任 ...
- linux 把ls -R格式化成树状结构
谁能写脚本把linux中的ls -R命令的结果格式化成树状结构? 最好是shell脚本!欢迎讨论! 参与讨论有可能意外获取iPhone6哦~~