代码全wa了
#include <iostream>
#define ll long long
using namespace std;
const int MN=1e5+5;
ll N,ans,P,num[MN],mod[MN];
int exgcd(ll a,ll b,ll &x,ll &y){
if (b==0) {
x=1,y=0;
return a;
}
int d=exgcd(b,a%b,x,y);
int z=x; x=y, y=z-(a/b)*y;
return d;
}
void solve(){
ans=num[1],P=mod[1];
for (int i=2; i<=N; i++){
ll tx,ty;
ll td=exgcd(P,mod[i],tx,ty);
tx=tx*abs((ans-num[i])/td);
ans=P*tx+ans;
P=P*mod[i]/td;
ans%=P;
}
}
int main(){
cin>>N;
for (int i=1; i<=N; i++) cin>>mod[i]>>num[i];
solve();
cout<<(ans%P+P)%P;
return 0;
}
大佬来水贴也行啊