北大ACM(POJ1006-Biorhythms)

Question:http://poj.org/problem?id=1006
问题点:孙子定理
 1 Memory: 248K        Time: 0MS
 2 Language: C++        Result: Accepted
 3
4 #include <iostream> 5 6 using namespace std; 7 int getGCD(int a,int b)//Greatest Common Divisor 8 { 9 if(a<b){a+=b;b=a-b;a=a-b;} 10 if(b==1) return 1; 11 else if(a%b==0) return a/b; 12 else return getGCD(b,a%b); 13 } 14 int getLCM(int a,int b)//Lowest Common Multiple 15 { 16 return a*b/getGCD(a,b); 17 } 18 int getMod1(int a,int b)//get N. a*N mod b ==1 19 { 20 int N=0; 21 while(a*N%b!=1){N++;} 22 return a*N; 23 } 24 int main() 25 { 26 int p,e,i,d,cnt=1; 27 int pe=getMod1(getLCM(23,28),33); 28 int pi=getMod1(getLCM(23,33),28); 29 int ei=getMod1(getLCM(28,33),23); 30 while(true) 31 { 32 cin>>p>>e>>i>>d; 33 if(p==-1&&e==-1&&i==-1&&d==-1) return 0; 34 int m=(ei*p+pi*e+pe*i)%(23*28*33)-d; 35 if(m<=0) m+=23*28*33; 36 cout<<"Case "<<cnt++<<": the next triple peak occurs in "<<m<<" days."<<endl; 37 } 38 }

 

 

转载于:https://www.cnblogs.com/TYcnblogs/p/poj1006.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值