首页 > 其他 > 详细

北大ACM(Question-1006)

时间:2016-01-09 15:24:14      阅读:276      评论:0      收藏:0      [点我收藏+]
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 }

 

 

北大ACM(Question-1006)

原文:http://www.cnblogs.com/TYcnblogs/p/poj1006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!