const int N = 15;
int n;
LL yu[N], mo[N];
LL exgcd(LL a, LL b, LL &x, LL &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
LL r = exgcd(b, a % b, x, y);
LL tmp = y;
y = x - (a / b) * y;
x = tmp;
return r;
}
LL CRT(LL *yu, LL *mo, int num)
{
LL M = 1, ans = 0, x, y;
for(int i = 0; i < num; i++)
M *= mo[i];
for(int i = 0; i < num; i++)
{
LL w = M / mo[i];
exgcd(w, mo[i], x, y);
ans = (ans + yu[i] * x * w) % M;
}
return (ans + M) % M;
}
【中国剩余定理】
最新推荐文章于 2023-07-25 18:59:37 发布