This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<bits/stdc++.h>
usingnamespacestd;
#define int long long
#define endl "\n"
constintN=20;
typedef__int128INT128;
intn;// 同余方程个数
inta[N];// 除数数组
intm[N];// 余数数组
intA=1;// 除数累乘积
intx,y;// (x,y)是方程 Mi * x + m[i] * y = 1的一个解,x是Mi关于m[i]的逆元
intres;// 最小整数解
// 扩展欧几里得模板
intexgcd(inta,intb,int&x,int&y){
if(!b){
x=1,y=0;
returna;
}
intd=exgcd(b,a%b,y,x);
y-=a/b*x;
returnd;
}
// 中国剩余定理模板
voidCRT(){
// 一、预处理
for(inti=1;i<=n;i++){
cin>>a[i]>>m[i];// 读入除数数组和余数数组
m[i]=(m[i]%a[i]+a[i])%a[i];// ① 预算余数为正数: r[i]可能为负数,预处理成正数,本题没有这个要求,但考虑到通用模板,加上了这块代码