結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
tabr
|
| 提出日時 | 2020-05-05 17:19:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 248 ms / 9,973 ms |
| コード長 | 1,141 bytes |
| コンパイル時間 | 1,741 ms |
| コンパイル使用メモリ | 168,144 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-16 23:24:04 |
| 合計ジャッジ時間 | 2,784 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
bool is_prime(unsigned long long n) {
if (n < 2) {
return false;
}
vector<unsigned long long> bases = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
unsigned long long s = __builtin_ctzll(n - 1), d = n >> s;
for (auto a : bases) {
unsigned long long p = 1, i = s, j = d, k = a;
while (j > 0) {
if (j & 1) {
p = (__int128)p * k % n;
}
k = (__uint128_t)k * k % n;
j >>= 1;
}
while (p != 1 && p != n - 1 && a % n && i--) {
p = (__uint128_t)p * p % n;
}
if (p != n - 1 && i != s) {
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
cout << x << " ";
int j = 0;
if (is_prime(x)) {
j = 1;
}
cout << j << '\n';
}
return 0;
}
tabr