中国剩余定理

G - 中国剩余定理
Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

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.
解释:

8中国剩余定理编辑

在中国古代劳动人民中,长期流传着“隔墙算”、“剪管术”、“秦王暗点兵”等数学游戏。有一首“孙子歌”,甚至远渡重洋,输入日本:
“三人同行七十稀,五树梅花廿一枝,
七子团圆正半月,除百零五便得知。”
这些饶有趣味的数学游戏,以各种不同形式,介绍世界闻名的“孙子问题”的解法,通俗地反映了中国古代数学一项卓越的成就。“孙子问题”在现代数论中是一个一次同余问题,它最早出现在中国公元四世纪的数学著作《 孙子算经》中。《孙子算经》卷下“物不知数”题说:有物不知其数,三个一数余二,五个一数余三,七个一数又余二,问该物总数几何?显然,这相当于求不定方程组
N=3x+2,N=5y+3,N=7z+2
的正整数解N,或用现代数论符号表示,等价干解下列的一次同余组。
《孙子算经》所给答案是N=23。由于孙子问题数据比较简单,这个答数通过试算也可以得到。但是《孙子算经》并不是这样做的。“物不知数”题的术文指出解题的方法多三三数之,取数七十,与余数二相乘;五五数之,取数二十一,与余数三相乘;七七数之,取数十五,与余数二相乘。将诸乘积相加,然后减去一百零五的倍数。列成算式就是:
N=70×2+21×3+15×2-2×105。
这里105是模数3、5、7的最小公倍数,容易看出,《孙子算经》给出的是符合条件的最小正整数。对于一般余数的情形,《孙子算经》术文指出,只要把上述算法中的余数2、3、2分别换成新的余数就行了。以R1、R2、R3表示这些余数,那么《 孙子算经》相当于给出公式
N=70×R1+21×R2+15×R3-P×105(p是整数)。
解答:
#include<stdio.h>
int main()
{
    long long  a[10],d;
    long long  i,t,j,s;
    long long  b=23*28*33;//运用孙子定理的前期,所有除数的总积。
    long long f[3];
    f[0]=23;f[1]=28;f[2]=33;//除数
    int q=0;
    while(scanf("%I64d%I64d%I64d%I64d",&a[0],&a[1],&a[2],&d)!=EOF)//余数
{

            q++;
            if(a[0]==-1&&a[1]==-1&&a[2]==-1&&d==-1)
                break;
                s=0;
            for(i=0;i<3;i++)
            {
                t=b/f[i];
                if(t%f[i]!=0)
                for(j=1;(t*j)%f[i]!=1;j++);//判定j值,保证余数为一。
                s+=t*a[i]*j;//得数相加


            }
              s=s-d+21252;//减去已经过的日子
            s=s%b;
             if(s==0)
                    s=21252;//排除特殊情况
            printf("Case %d: the next triple peak occurs in %I64d days.\n",q,s);
        }
        return 0;
    }


内容概要:本文档详细介绍了基于MATLAB实现多目标差分进化(MODE)算法进行无人机三维路径规划的项目实例。项目旨在提升无人机在复杂三维环境中路径规划的精度、实时性、多目标协调处理能力、障碍物避让能力和路径平滑性。通过引入多目标差分进化算法,项目解决了传统路径规划算法在动态环境和多目标优化中的不足,实现了路径长度、飞行安全距离、能耗等多个目标的协调优化。文档涵盖了环境建模、路径编码、多目标优化策略、障碍物检测与避让、路径平滑处理等关键技术模块,并提供了部分MATLAB代码示例。 适合人群:具备一定编程基础,对无人机路径规划和多目标优化算法感兴趣的科研人员、工程师和研究生。 使用场景及目标:①适用于无人机在军事侦察、环境监测、灾害救援、物流运输、城市管理等领域的三维路径规划;②通过多目标差分进化算法,优化路径长度、飞行安全距离、能耗等多目标,提升无人机任务执行效率和安全性;③解决动态环境变化、实时路径调整和复杂障碍物避让等问题。 其他说明:项目采用模块化设计,便于集成不同的优化目标和动态环境因素,支持后续算法升级与功能扩展。通过系统实现和仿真实验验证,项目不仅提升了理论研究的实用价值,还为无人机智能自主飞行提供了技术基础。文档提供了详细的代码示例,有助于读者深入理解和实践该项目。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值