题意:
$\left\{ {\begin{array}{*{20}{l}}
{res = {r_1}\,\bmod \,{m_1}}\\{res = {r_2}\,\bmod \,{m_2}}\\{res = {r_3}\,\bmod \,{m_3}}\end{array}} \right.$解题关键:由于模数互质,直接crt即可。
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 typedef long long ll; 9 ll x,y,r[10],m[10],n=3;10 ll extgcd(ll a,ll b,ll &x,ll &y){11 ll d=a;12 if(b) d=extgcd(b,a%b,y,x),y-=a/b*x;13 else x=1,y=0;14 return d;15 }16 ll inv(ll t,ll mod){ extgcd(t,mod,x,y);return (x+mod)%mod;}17 ll crt(int n,ll *r,ll *m){18 ll M=1,ret=0;19 for(int i=0;i >r[0]>>r[1]>>r[2]>>a){31 if(a==-1&&r[0]==-1&&r[1]==-1&&r[2]==-1) break;32 printf("Case %d: ",Case++);33 ll tmp=23*28*33;34 ll ans=((crt(3,r,m)-a)%tmp+tmp)%tmp;35 if(ans==0) ans+=tmp;36 printf("the next triple peak occurs in %lld days.\n",ans);37 }38 }