boolmiller_rabin(ll n){ if (n <= 2) return n == 2; int d = n - 1, t = 0; while (d % 2 == 0) d /= 2, ++t; rep(i, 0, T) { // T 是测试次数, p 是测试基 ll x = ksm(p[i] % (n - 2) + 2, d, n); if (x == 1 || x == n - 1) continue; // 无效的二次探测 for (int j = 0; j < t; ++j, x = x * x % n) if (x != n - 1 && x != 1 && x * x % n == 1) return0; if (x != 1) return0; // 费马判素 } return1; }