首页 > 编程知识 正文

中国剩余定理公式通解,python浪漫代码

时间:2023-05-03 23:26:24 阅读:134052 作者:1874

这个问题可以用初等数论中同余方程的求解问题。 使用同余的符号,可以将上述问题转换为以下同余方程:

x2 )模式3;

x3 )模式5;

x2 )模式7;

可以看出上述联合方程的解不是唯一的。 因为,如果x是一个解,则x 357k=x 105k也是该联合方程式的一个解,这里的k可以是任意整数。 其实,从3、5、7两个互质可以看出,上述同余方程的任意两个解相差105的倍数。 因此,在获得“最小正整数解”x0时,每个解可以表示为x=x0 105k。

如何求上述同余方程的一个解? 模糊电源智能地将问题转化为以下三个非常特殊的同余方程的解

a1 (模式3 ); b0 (模式3; C0 (模式3;

a0 (模式5; B1(mod5); C0 (模式5;

a0 (模7; B0 (模7; C1 )模式7;

很明显,如果求出a、b、c的值的组,2a 3b 2c就会成为原来的联合方程式的一个解,如果用105将其解除,就会成为求出对应的馀数的最小整数解。 通过简单的计算,可以知道a可以得到70,b可以得到21,c可以得到15。 因此,用2 a3b 2c=233,105除的馀数是23,是求出的最小正整数解。

Biorhythms

问题描述

somepeoplebelievethattherearethreecyclesinaperson ' slifethatstartthedayheorsheisborn.thesethreecyclesarethephysical,emotional andtheyhaveperiodsoflengths 23、28、and 33 days、respectively.thereisonepeakineachperiodofacycle.atthepeakofacycle、 apersonperformsathisorherbestinthecorrespondingfield (physical,emotional or mental ).For example,if it is the mental curve,the

sincethethreecycleshavedifferentperiods、 thepeaksofthethreecyclesgenerallyoccuratdifferenttimes.wewouldliketodeterminewhenatriplepeakoccurs (occurinthesameday ) youwillbegiventhenumberofdaysfromthebeginningofthecurrentyearatwhichoneofitspeaks (notnecessarilythefirst ) )。 occurs.youwillalsobegivenadateexpressedasthenumberofdaysfromthebeginningofthecurrentyear.youtaskistodeterminethenumberofd arofd triple peak.thegivendateisnotcounted.for example,ifthegivendateis 10 andthenexttriplepeakoccursonday 12,the answer is 2, not3. ifatriplepeakoccursonthegivendate,youshouldgivethenumberofdaystothenextoccurrenceofatriplepeak。

输入

youwillbegivenanumberofcases.theinputforeachcaseconsistsofonelineoffourintegersp,e,I,and d. The values p,e, andiarethenumberofdaysfromthebeginningofthecurrentyearatwhichthephysical,emotional,and intellectual cycles peak, respectively.thevaluedisthegivendateandmaybesmallerthananyofp,e,ori.allvaluesarenon-negativeandatmost 365, andyoumayassumethatatriplepeakwilloccurwithin 21252 daysofthegivendate.theendofinputisindicatedbyalineinwhichp=e=I-d-d

Output

For each test case,printthecasenumberfollowedbyamessageindicatingthenumberofdaystothenexttriplepeak,in the form:

case 1: thenexttriplepeakoccursin 1234 days。

usethepluralform ` ` days ' ' eveniftheansweris 1。

样品输入

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

样品输出

case 1: thenexttriplepeakoccursin 21252 days。

case 2: thenexttriplepeakoccursin 21152 days。

case 3: thenexttriplepeakoccursin 19575 days。

case 4: thenexttriplepeakoccursin 16994 days。

case 5: thenexttriplepeakoccursin 8910 days。

case 6: thenexttriplepeakoccursin 10789 days。

PKU

1 #包含

2

3使用命名空间TD; 4

5intmain(6)6 {7 int k=0; 8 intp,e,I,d; 9 cinpeid; 10while(p!=-1e!=-1i!=-1d!=-1 ) 11(12k; 13 intt=(p * 5544 e * 14421 I * 1288-d 21252 )! 252; 14if(t==0) t=21252; 15 coutpeid; 17 ) 18return0; 19 }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。