中国剩余定理
//中国剩余定理
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=50;
LL a[MAXN];
LL b[MAXN];
int k;
LL mul(LL a,LL b,LL mod)
{
LL res=0;
while(b){
if(b&1LL) res=(res+a)%mod;
a=(a+a)%mod;
b>>=1;
}
return res;
}
LL exgcd(LL a,LL b,LL &x,LL &y)
{
if(b==0){ x=1,y=0;return a; }
LL d=exgcd(b,a%b,x,y);
LL z=x;x=y;y=z-y*(a/b);
return d;
}
LL China()
{
LL ans=0,lcm=1,x,y;
for(int i=1;i<=k;i++) lcm*=b[i];
for(int i=1;i<=k;i++){
LL tp=lcm/b[i];
exgcd(tp,b[i],x,y);
x=(x%b[i]+b[i])%b[i];//x要为最小的非负整数解
ans=(ans+mul(a[i],mul(tp,x,lcm),lcm))%lcm;//三个乘起来可能会爆LL,就需要用快速乘/**/
}
return (ans+lcm)%lcm;
}
int main()
{
scanf("%d",&k);
for(int i=1;i