結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー TlapesiumTlapesium
提出日時 2020-08-15 19:47:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,247 bytes
コンパイル時間 3,157 ms
コンパイル使用メモリ 214,404 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 14:07:22
合計ジャッジ時間 4,856 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 299 ms
5,376 KB
testcase_05 AC 311 ms
5,376 KB
testcase_06 AC 168 ms
5,376 KB
testcase_07 AC 163 ms
5,376 KB
testcase_08 AC 168 ms
5,376 KB
testcase_09 AC 534 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'bool isprime_int64(ull)':
main.cpp:29:27: warning: 'd' may be used uninitialized [-Wmaybe-uninitialized]
   29 |                 if (modpow(a[i], d, N) == 1)continue;
      |                     ~~~~~~^~~~~~~~~~~~
main.cpp:17:20: note: 'd' was declared here
   17 |         ull s = 0, d;
      |                    ^

ソースコード

diff #

#pragma GCC optimize("O3")
//#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

bool isprime_int64(ull N) {
	if (N == 2)return 1;
	if (N % 2 == 0 || N <= 2)return 0;
	ull s = 0, d;
	ull a[] = { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 };
	for (ull i = N - 1; i % 2 == 0; i /= 2)s++, d = i / 2;
	auto modpow = [](__int128 x, __int128 k, __int128 mod) {
		__int128 res = 1;
		for (x %= mod; k; x = x * x % mod, k >>= 1)
			if (k & 1) res = res * x % mod;
		return res;
	};
	for (int i = 0; i < 7; i++) {
		bool flag = 1;
		if (N <= a[i])continue;
		if (modpow(a[i], d, N) == 1)continue;
		for (int j = 0; j < s; j++) if (modpow(a[i], d * (1ULL << j), N) == N - 1) {
			flag = 0;
			break;
		}
		if (flag)return 0;
	}

	return 1;
}

int main() {
	io_init;
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		ull x;
		cin >> x;
		cout << x << " " << isprime_int64(x) << endl;
	}

}
0