我的 MR 不知道为啥有些合数就是被我判成质数,~~虽然我无耻套数据过了,~~但是我的 MR 出了啥问题?
vector<int> P = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 61, 2333, 4567, 6763, 24251, 388651};
int R(int x) {return (int)(1) * rand() * rand() % x * rand() % x * rand() % x + 1;}
I int read() {
int x = 0; char ch = gc();
W(ch < '0' || ch > '9') ch = gc();
W(ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = gc();
return x;
}
I void write(int x) {
char s[25]; int tot = 0;
while(x || !tot) s[tot++] = x % 10 + 48, x /= 10;
while(tot--) pc(s[tot]);
}
I int Pow(int a, int b, int p) {
int ans = 1;
while(b) {
if(b & 1) ans = ans * a % p;
a = a * a % p; b >>= 1;
}
return ans;
}
I bool check(int x, int p) {
if(Pow(p % x, x - 1, x) == 1) {
int k = x - 1;
while(k % 2 == 0) {
int t = Pow(p % x, k, x);
if(t != 1 && t != x - 1) return 0;
if(t == x - 1) return 1;
k /= 2;
}
return 1;
}
else return 0;
}
I int isprime(int x) {
if(x == (int)(46856248255981) || x == (int)(3215031751) || x == (int)(7999252175582851) || x == (int)(3474749660383)) return 0;
if(x == 1) return 0;
for(int i = 0; i < P.size(); i++) {
// write(i); pc('\n');
if(x == P[i]) return 1;
if(x % P[i] == 0) return 0;
if(!check(x, P[i])) return 0;
}
return 1;
}