\[\begin{cases}x≡a_1(mod)m_1\\x≡a_2(mod)m_2\\ \cdots \cdots\\x≡a_n(mod)m_n\\\end{cases}\]
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,M=1;
LL a[15],b[15];
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,y,x);
    y-=x*(a/b);
    return d;
}
void Intchina(){
    LL x,y,ans=0;
    for(LL i=1;i<=n;i++){
        LL Mi=M/a[i];
        exgcd(Mi,a[i],x,y);
        ans=((ans+Mi*x*b[i])%M+M)%M;
    }
    printf("%lld\n",ans);
}
int main(){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&a[i],&b[i]);
        M*=a[i];
    }
    Intchina();
    return 0;
}
原文:https://www.cnblogs.com/PPXppx/p/10501600.html