模板-->中国剩余定理[互质版本]

如果有相应的OJ题目,欢迎同学们提供相应的链接

相关链接

简单的测试

None

代码模板

/*
 * TIME COMPLEXITY:O(nlogm)
 * PARAMS:
 *      a       x==ai(mod mi)
 *      m
 *      n       the number of equation.
 */
int crt(int a[],int m[],int n){
    int M=1;
    for(int i=0;i<n;i++) M*=m[i];
    int ret=0;
    for(int i=0;i<n;i++){
        int x,y;
        int tm=M/m[i];
        extend_gcd(tm,m[i],x,y);
        ret=(ret+tm*x*a[i])%M;
    }
    return (ret+M)%M;
}
原文地址:https://www.cnblogs.com/mRRRR/p/5540298.html