結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
|
| 提出日時 | 2020-04-29 15:38:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,206 bytes |
| コンパイル時間 | 1,751 ms |
| コンパイル使用メモリ | 168,536 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-18 17:50:02 |
| 合計ジャッジ時間 | 3,081 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 6 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<ll,ll>;
const ll INF = 1e18;
const int MOD = 1000000007;
long long modpow(long long x, long long n,long long mod) {
long long ret = 1;
while (n > 0) {
if (n & 1) ret = (ret * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return ret;
}
bool Miller_Rabin(long long x){
if(x == 0) return false;
if(x == 1) return false;
if(x == 2) return true;
if(x%2 == 0) return false;
long long d = x - 1;
while(d%2 == 0) d /= 2;
random_device rand;
mt19937 mt(rand());
uniform_int_distribution<long long> random_maker(1,x-1);
for(int i = 0;i < 20; ++i){
long long a = modpow(random_maker(mt),d,x);
long long s = d;
while(s != x-1 && a != 1 && a != x-1){
a = (a * a)%x;
s <<= 1;
}
if(a != x-1 && s%2 == 0) return false;
}
return true;
}
int main(){
int n;
cin >> n;
while(n--){
ll x; cin >> x; cout << x << " " ;
cout << (Miller_Rabin(x) ? 1 : 0) << endl;
}
return 0;
}