使33×28×a被23除余1,用33×28×8=5544;
使23×33×b被28除余1,用23×33×19=14421;
使23×28×c被33除余1,用23×28×2=1288。
因此有(5544×p+14421×e+1288×i)% lcm(23,28,33) =n+d
#include<cstdio>
#include<iostream>
#define lcm 21252
#include<algorithm>
using namespace std;
int main() {
int p,e,i,d,count=1,ans;
while(cin>>p>>e>>i>>d) {
if(p==-1&&e==-1&&i==-1&&d==-1)
break;
ans=(5544*p+14421*e+1288*i-d+lcm)%lcm;
if(ans==0)
ans=lcm;
printf("Case %d: the next triple peak occurs in %d days.\n",count++,ans);
}
}
链接