题目大意
略。。。有中文。。。
题解
就是解同余方程组
x≡(p-d)(mod 23)
x≡(e-d)(mod 28)
x≡(i-d)(mod 33)
最简单的中国剩余定理应用。。。。
代码:
#include<iostream> #include<cstdio> using namespace std; void gcd(int a,int b,int &d,int &x,int &y) { if(!b) { d=a,x=1,y=0; } else { gcd(b,a%b,d,y,x),y-=x*(a/b); } } int main() { int p,e,d,i,a1,a2,a3,M1,M2,M3,t=0; while(cin>>p>>e>>i>>d&&p+e+i+d>=0) { int x=0,y,q; a1=p-d,a2=e-d,a3=i-d; M1=924,M2=759,M3=644; gcd(23,M1,q,q,y),x=(x+y*M1*a1)%21252; gcd(28,M2,q,q,y),x=(x+y*M2*a2)%21252; gcd(33,M3,q,q,y),x=(x+y*M3*a3)%21252; x=(x%21252+21252)%21252,x=x?x:21252; printf("Case %d: the next triple peak occurs in %d days. ",++t,x); } return 0; }