結果

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

テストケース

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

ソースコード

diff #

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [1234567]
    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 < 100:
        return 0
    return isPrimeMR(n)

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

0