結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー RhoRho
提出日時 2019-10-16 01:21:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 940 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 166,804 KB
実行使用メモリ 814,804 KB
最終ジャッジ日時 2023-08-11 22:32:47
合計ジャッジ時間 4,574 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
random_device rd;
mt19937 mt(rd());
int modpro(int x, int n, int md) {
	if (!n)return 0;
	int res = modpro((x + x)%md, n >> 1, md);
	if (n & 1)res = (res + x) % md;
	return res;
}
int modpow(int x, int n, int md) {
	if (!n)return 1;
	int res = modpow(modpro(x,x,md), n >>1, md);
	if (n & 1)res = modpro(res,x,md);
	return res;
}

int gcd(int a, int b) {
	if (!b)return a; return gcd(b, a%b);
}
bool isprime(int p) {
	if (p == 2 || p == 3 || p == 5)return true;
	if (p == 1 || p == 4)return false;
	
	for(int z=0;z<5000;++z) {
		int b = mt() % (p - 2) + 2;
		if (gcd(b, p) > 1) {
			return false;
		}
		if (modpow(b, p - 1, p) > 1) {
			return false;
		}
	}
	return true;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	int p;
	for (int i = 0; i < n; i++) {
		cin >> p;
		cout << p;
		if (isprime(p))puts(" 1");
		else puts(" 0");
	}
}
0