QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#722512 | #249. Miller Rabin 算法 | AutomatiC__ | WA | 22ms | 3816kb | C++23 | 1.3kb | 2024-11-07 19:19:14 | 2024-11-07 19:19:15 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cstdlib>
#include <bitset>
#include <deque>
#include <random>
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll binpow(ll a, ll b, ll mod) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
bool miller_rabin(ll n) {
if (n < 3 || n % 2 == 0) return n == 2;
if (n % 3 == 0) return n == 3;
ll u = n - 1, t = 0;
while (u % 2 == 0) u /= 2, ++t;
for (int i = 1; i <= 9; i++) {
ll a = rand() % (n - 3) + 2;
ll v = binpow(a, u, n);
if (v == 1) continue;
int s = 0;
for (s = 0; s < t; s++) {
if (v == n - 1) break;
v = v * v % n;
}
if (s == t) return false;
}
return true;
}
int main() {
mt19937_64 rand(time(0));
ll x;
while (cin >> x) {
if (miller_rabin(x)) {
cout << "Y" << endl;
} else {
cout << "N" << endl;
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 22ms
memory: 3816kb
input:
996581938833575363 971646509461160317 773155992127361153 161603952726515268 540879144500456953 476831214764178553 784255927154201144 671096087619405061 805545190025269709 339546334309245137 337726347922962343 222956293307015293 809183111090275843 799050063298926344 691718101820598109 646220213113313...
output:
N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N ...
result:
wrong answer 2nd lines differ - expected: 'Y', found: 'N'