結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー masa_aamasa_aa
提出日時 2020-09-21 01:45:28
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 674 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 78,676 KB
最終ジャッジ日時 2023-08-11 23:10:00
合計ジャッジ時間 4,022 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,436 KB
testcase_01 AC 69 ms
71,156 KB
testcase_02 AC 74 ms
71,392 KB
testcase_03 AC 70 ms
71,148 KB
testcase_04 WA -
testcase_05 AC 450 ms
78,172 KB
testcase_06 AC 291 ms
78,640 KB
testcase_07 AC 286 ms
78,592 KB
testcase_08 AC 282 ms
77,776 KB
testcase_09 AC 670 ms
77,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Miller(N):
    v = [2, 7, 61] if N < 4_759_123_141 else [2, 3, 5, 7, 11, 13, 17] if 341_550_071_728_321 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    if N < 2:
        return 0
    if N in v:
        return 1
    d = N - 1
    s = 0
    while d % 2 == 0:
        d //= 2
        s += 1

    for a in v:
        if pow(a, d, N) != 1:
            ok = True
            for r in range(s):
                if pow(a, d * 1 << r, N) == N - 1:
                    ok = 0
                    break
            if ok:
                return 0
    return 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
    n = int(input())
    print(n, Miller(n))
0