题意
给出a,b,c,d,求最小的 S 满足:
S≡b(mod 28)
S≡c(mod 33)
输出S-d
题解
orz zzk 中国剩余定理
直接求这个方程组就好了
#include<cstdio>
#include<algorithm>
#define T 21252
using namespace std;
int s,ans,a[4],b[4]={0,23,28,33};
int exgcd(int a,int b,int &x,int &y){
if(!b){
x=1,y=0;
return a;
}
int r=exgcd(b,a%b,x,y),t;
t=x,x=y,y=t-a/b*y;
return r;
}
inline int China(int n){
int res=0;
for(int i=1;i<=n;++i){
int x,y,w=T/b[i];exgcd(w,b[i],x,y);
res=(res+w*x*a[i])%T;
}
return (res+T)%T;
}
int main(){
// freopen("testdata.in","r",stdin);
// freopen("testdata.out","w",stdout);
int test=0;
while(~scanf("%d%d%d%d",&a[1],&a[2],&a[3],&s)){
if(a[1]==-1) break;
ans=(China(3)-s+T)%T;
printf("Case %d: the next triple peak occurs in %d days.\n",++test,ans<=0?ans+T:ans);
}
return 0;
}