![模板-->中国剩余定理[互质版本] 模板-->中国剩余定理[互质版本]](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
如果有相应的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;
}