結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー Kiri8128Kiri8128
提出日時 2020-05-06 00:08:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 596 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 76,928 KB
最終ジャッジ日時 2024-04-29 13:56:25
合計ジャッジ時間 2,392 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
51,840 KB
testcase_01 AC 41 ms
51,456 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 42 ms
51,712 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 202 ms
76,544 KB
testcase_09 AC 331 ms
76,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 3, 5, 7, 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
    for p in P:
        if n % p == 0:
            return 0
    return isPrimeMR(n)

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