結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー Kiri8128Kiri8128
提出日時 2020-05-06 00:06:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 524 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,380 KB
実行使用メモリ 77,820 KB
最終ジャッジ日時 2024-04-29 13:55:45
合計ジャッジ時間 1,932 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 34 ms
52,224 KB
testcase_02 AC 35 ms
51,840 KB
testcase_03 AC 36 ms
52,608 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 155 ms
77,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [1234577]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = y * y % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1

P = [2, 3, 5, 7, 11, 13, 17, 19]
setP = set(P)
def isPrime(n):
    if n in setP:
        return 1
    if n < 20:
        return 0
    return isPrimeMR(n)

N = int(input())
for _ in range(N):
    n = int(input())
    print(n, isPrime(n))
0