POJ 1006 Biorhythms

來源:互聯網
上載者:User

中國剩餘定理,學習了..

具體的定理講起來可能難以理解,百度一下就可以了..這裡舉個小例子吧..

比如 x%3=1,x%4=2.x%5=4,求x的最小值,分別求兩兩最小公倍數(4,5)=20,(3,5)=15,(3,4)=12,三者公倍數(3,4,5)=60..

現在就是使20,15,12分別乘以某個數使他們模3,4,5的值相同.

因此有20*2%3=1,15*3%4=1,12*3%5=1..然後40*3+45*4+36*5=274

因為比60大,所以274-60*4=34,即為所求數..

#include <stdio.h>//(23,28)=644 1288%33=1//(23,33)=759 14421%28=1//(28,33)=924 5544%23=1//(23,28,33)=21252int main(){int a,b,c,d,i=1;while(scanf("%d%d%d%d",&a,&b,&c,&d)){if(a==-1&&b==-1&&c==-1&&d==-1)break;int res=(1288*c+14421*b+5544*a+21252-d)%21252;if(res==0)res=21252;printf("Case %d: the next triple peak occurs in %d days.\n",i++,res);}}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.