中国剩余定理(CRT)+ exgcd
LL CRT(int k, LL* a, LL* r) {
  LL n = 1, ans = 0;
  for (int i = 1; i <= k; i++) n = n * r[i];
  for (int i = 1; i <= k; i++) {
    LL m = n / r[i], b, y;
    exgcd(m, r[i], b, y);  // b * m mod r[i] = 1
    ans = (ans + a[i] * m * b % n) % n;
  }
  return (ans % n + n) % n;
}
处理模数非质数问题,可以用CRT+LUCAS定理求解(模数分解为数量为1的质数)
https://www.luogu.com.cn/problem/P2480
                    
                
                
            
        
浙公网安备 33010602011771号