poj 1006 Biorhythms(中国剩余定理)

Biorhythms
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 94863 Accepted: 29139

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.

中国剩余定理:同余定理:
在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。具体解法分三步:
  1. 找出三个数:从3和5的公倍数中找出被7除余1的最小数15,从3和7的公倍数中找出被5除余1 的最小数21,最后从5和7的公倍数中找出除3余1的最小数70。
  2. 用15乘以2(2为最终结果除以7的余数),用21乘以3(3为最终结果除以5的余数),同理,用70乘以2(2为最终结果除以3的余数),然后把三个乘积相加(15*2+21*3+70*2)得到和233。
  3. 用233除以3,5,7三个数的最小公倍数105,得到余数23,即233%105=23。这个余数23就是符合条件的最小数。


即:对于n1,n2,n3三个数,某个数m对n1,n2,n3分别取模为a,b,c;

a = m%n1;

b = m%n2;

c = m%n3;

此时求m的值。

(1)求n1,n2的最小公倍数的倍数中模n3为1的数m3

(2)求n1,n3的最小公倍数的倍数中模n2为1的数m2

(2)求n1,n2的最小公倍数的倍数中模n1为1的数m1

m = (m1*a+m2*b+m3*c)%(n1*n2*n3)

/**
    中国剩余定理:同余定理
    
*/
#include <stdio.h>
int main()
{
    int p,e,i,d,k=1,days;
    int num1,num2,num3;
    for(int j = 1; ; j++)
    if(28*33*j%23==1){num1 = 33*28*j;break;}
    for(int j = 1; ; j++)
    if(23*33*j%28==1){num2 = 23*33*j;break;}
    for(int j = 1; ; j++)
    if(23*28*j%33==1){num3 = 23*28*j;break;}
    while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF)
    {
        if(p==-1&&e==-1&&i==-1&&d==-1)break;
        days = (p*num1+e*num2+i*num3-d)%(23*33*28);
        if(days<=0)days = 21252-d;
        printf("Case %d: the next triple peak occurs in %d days.\n",k++,days);
    }
    return 0;
}
Netapp FAS2750热备盘替换失败问题分析与解决 本文深入分析了Netapp FAS2750存储系统中热备盘替换失败的故障现象,揭示了磁盘分区属主不匹配导致数据同步无法启动的根本原因。通过详细的排查步骤和解决方案,帮助运维人员快速恢复aggr状态,并提供了长期预防措施和最佳实践建议,确保存储系统的高可用性。 阅读详情

相关推荐

NVIDIA显卡驱动历史版本全攻略:从官网隐藏入口到精准下载

本文详细介绍了如何获取NVIDIA显卡驱动历史版本的完整攻略,包括官网隐藏入口的揭秘、精准筛选驱动版本的技巧以及安装避坑指南。特别针对游戏玩家、创作者和老显卡用户提供了实用建议,帮助用户解决驱动兼容性问题,提升显卡性能。

m2n3o4p5的博客 3860

poj1006 Biorhythms 中国剩余定理

中国剩余定理 在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3 余2),五五数之剩三(除以5 余3),七七数之剩二(除以7 余2),问物几何?” 做这个问题之前,首先要清楚两条定理 如果有a%b=c,则有(a+k b)%b=c(k 为非零整数)。两个数相加,如果存在一个加数,不能被整数a整除,那么它们的和,就不能被整数a整除。 如果a%b=c,那么(a*k)%b=(a%b+...

qq_41746080的博客 236

手把手教你:在联想/戴尔笔记本上安装华为电脑管家,实现多屏协同(附详细避坑步骤)

本文详细指导如何在联想、戴尔等非华为笔记本上安装华为电脑管家,实现多屏协同功能。从硬件兼容性检查到定制化安装流程,再到功能调优与异常处理,提供了一套完整的解决方案,帮助用户突破品牌限制,享受华为生态的高效办公体验。

weixin_30251829的博客 917

POJ-1006 Biorhythms 中国剩余定理

POJ-1006 Biorhythms 文章目录POJ-1006 Biorhythms思路:推导细节AC代码 由于题目过于冗长,在此只描述大致题意:人出生就伴随:体力,情感和智力三个生理周期,他们的周期分别为23天,28天,33天,每个周期内有一天为该阶段的峰值,这一天人在对应的方面的表现的最好。一般情况下,这三天不会在同一天,现在分别给出三个日期,分别对应体力§,情感(e),智力(i)出现峰值的日期,以及一个起始日期(d),问:从起始日期开始,最少经过多少天三个方面同时到达峰值。 思路: 关于中国剩余

碳碳双键 212

如何使用AKShare作为OpenBB的数据源

`openbb_akshare`项目是 OpenBB 的数据源扩展。可以用于查询A股和港股数据

FinAnalyzer金融分析工具 3199

AUTOSAR R20-11标准下载!

这是公众号的第2篇推文,粉丝数49 Document Search Classic Platform Adaptive Platform Foundation 文档截图 以为会在明天的发布会之后才上线,没想到官网现在就悄悄放出来了。 中国由于网络问题,下载速度比较慢或者会中断。 “阅读原文”提供多种下载方式,可以在线浏览,可以集中下载也可单个文档下载。 如有增减我也会及时在公众号里通知大家,不过我觉得不会变动了。 整理不宜,好东西要分...

Adaptive_AUTOSAR的博客 1896

POJ 1006 Biorhythms (中国剩余定理)

题目链接:POJ 1006 Biorhythms 题意:给定p,e,i,d,分别表示三种状态出现的时间,d表示从第d天开始。求多少天后三个状态同时出现。 x=p mod 23 x=e mod 28 x=i mod 33 中国剩余定理。 AC代码: #include int exgcd(int a,int b,int &x,int &y) { if(

n-1 748

「Debug R」在从名字空间‘XVector’中出口方法时发现了不是S4通用的函数‘parallelSlotNames’...

每当R语言版本更新,Bioconductor的版本随之更替的时候,总会有一些神奇的报错会出现,比如说下面这种。 Error: package or namespace load failed for ‘GenomicRanges’: 在从名字空间‘XVector’中出口方法时发现了不是S4通用的函数‘parallelSlotNames’ 如果读中文读不懂,我们可以把它翻译成英文。 packa...

xuzhougeng blog 2006

POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)

POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)题意分析不妨设日期为x,根据题意可以列出日期上的方程:化简可得:根据中国剩余定理求解即可。代码总览#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; typedef int ll; ll p

Pengwill's Blog 410

目标检测YOLO实战应用案例100讲-基于YOLOv7的番茄采摘机械手场景感知及试验(下)

根据软件系统的设计需求,制定系统的可行性方案分析,编写系统的相关程序和 调试运行环境,对系统进行测试,以实现对番茄数据的采集及监测。登陆界面登陆后,进入选择界面,菜单包括了对番茄种植棚室的固定相机数据的监测、 对番茄采摘机械手的双目相机采集的番茄的静态、动态数据的获取、对番茄静态、动态数 据处理的功能菜单等选项。与利用人工去进行对于番茄果实的识别和数目的统计相比,番茄视觉系统自动记录番 茄数量以及红色已经成熟的番茄、青色未成熟番茄的数量,减轻人工记录的工作量,减少 人工记录的误差,从经济方面是可行的。

qq_36130719的博客 819

MATLAB与ROS联合仿真——实例程序搭建思路

MATLAB与ROS联合仿真——实例程序搭建思路

慕羽★的博客 5235

POJ 1006 Biorhythms(中国剩余定理)

题目地址:POJ 1006 学习了下中国剩余定理。参考的该博客,博客戳这里。 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么可以设三个数R1,R2,R3.R1为c2,c3的公倍数且余c1为1,同理,R2,R3也是如此,然后设z=R1*m1+R2*m2+R3*m3,那么z就是其中一个解,而且每隔(c1,c2,c3)的最小公倍数就是一个解。想要最小解的话,只

scf0920 1182

浏览器主页被2345劫持简单处理方法

本人比较常用的浏览器是IE和Chrome IE: 将网址修改为https://www.baidu.com 应用-确定-重新打开IE浏览器 或者win+r运行regedit打开注册表找到这个值   HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main下  和HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Main这个下面的StartPage ...

A soul tortured by desire 2万+

POJ - 1006 Biorhythms(CRT中国剩余定理)

前述:对做过的题目进行复习,顺便整合一下专题里面比较经典的数论题目。   POJ - 1006 Biorhythms   这是一道CRT的模板题,也是最经典的例题,题意就是人的体力,情感,智力分别有高峰周期m1=23,m2=28,m3=33,给定一个三者达到高峰的初始日期(从一年的第一天开始的日期),问重新达到高峰的日期与给定日期的差值,若求得的数小给定日期,则加上21252。因为三个周期满足

m0_37772713的博客 352

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

【poj1006-biorhythms】中国剩余定理

【poj1006-biorhythms】中国剩余定理 http://poj.org/problem?id=1006 题意:中国剩余定理的裸题。 题目可转化为求最小的x满足以下条件: x%23=a;x%28=b;x%33=c; 关于中国剩余定理可看我昨天的博文:http://www.cnblogs.com/KonjakJuruo/p/5176...

qq_25768269的博客 165

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

POJ 1006 Biorhythms 中国剩余定理

https://vjudge.net/problem/POJ-1006 思路:中国剩余定理。 #include<cstdio> using namespace std; typedef long long ll; ll a[3]; ll m[3]={23,28,33}; ll exgcd(ll a,ll b,ll &x,ll &y) { if(b==0) ...

xiji333的博客 242

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

POJ1006 Biorhythms —— 中国剩余定理

题目链接:https://vjudge.net/problem/POJ-1006 Biorhythms Time Limit:1000MS Memory Limit:10000K Total Submissions:141576 Accepted:45491 Description Some people b...

alince20008的博客 207

POJ1006-Biorhythms【中国剩余定理】

正题 题目链接:http://poj.org/problem?id=1006 题目大意 若干个p,e,i,dp,e,i,dp,e,i,d。已经知道 {(d+x)≡p(mod 23)(d+x)≡e(mod 28)(d+x)≡i(mod 33)\left\{\begin{matrix} (d+x)\equiv p(mod\ 23) \\ (d+x)\equiv e(mo...

QuantAsk 457

POJ1006 Biorhythms 中国剩余定理

题目链接:http://poj.org/problem?id=1006 题目大意:每个人从出生开始都有三个周期:物理,情感,智力周期,已知他们的周期时长分别为23天,28天和33天。每个周期当中都有一个高峰期,并把这三个周期公共的一个高峰期叫做三重高峰期。现在分别给出你三个数p,e,i,代表在从年初算起的第p天是物理高峰期,第e天是情感高峰期,第i天是智力高峰期(并不一定是第一个

AC_Gibson的专栏 616

【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms

题目链接:   http://poj.org/problem?id=1006   http://acm.hdu.edu.cn/showproblem.php?pid=1370 题目大意:   (X+d)%23=a1,(X+d)%28=a2,(X+d)%33=a3,给定a1,a2,a3,d,求最小的X。 题目思路:   【中国剩余定理】   23,28,33互素,可以套中国剩...

PHILIP0917的博客 197

Poj1006 Biorhythms 【中国剩余定理】

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 ...

qq_28640193的博客 428

poj 1006 Biorhythms (中国剩余定理模板)

http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力、感情和智力周期,它们的周期长度为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,智力周期的高峰,人会思维敏捷,精力容易高度集中。因为三个周期的周长不同,所以通常三个周期的高峰不会落在同一天。对于每个人,我们想知道何时三个高峰落在同...

deyou1988的专栏 274

POJ 1006 Biorhythms【中国剩余定理】

链接在此:中国剩余定理 Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 121949   Accepted: 38446 Description Some people believe that there are thr

nuanxin_520的专栏 355

POJ1006-Biorhythms 中国剩余定理

BiorhythmsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 143074 Accepted: 46000DescriptionSome people believe that there are three cycles in a person's life that start the day he or she is ...

imbabao的博客 252

[poj 1006] Biorhythms{中国剩余定理(CRT)}

题目 http://poj.org/problem?id=1006 解题思路 代码 #include<cstdio> #include<algorithm> using namespace std; int a,b,c,d,q1,q2,q3,w,j,ans,t; int main(){ q1=28*33,q2=23*33,q3=23*28,w=23*28*33; ...

Nowed 225
上一篇: 项目管理工具Redmine安装
下一篇: CUPS 'cupsd' RSS订阅NULL指针引用本地拒绝服务漏洞
weixin_33824363
博客等级 码龄11年 6143粉丝 1273原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值