結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー こまるこまる
提出日時 2020-12-01 23:46:14
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 612 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-04-29 14:40:33
合計ジャッジ時間 2,756 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,456 KB
testcase_01 AC 40 ms
51,968 KB
testcase_02 AC 40 ms
51,840 KB
testcase_03 AC 44 ms
51,968 KB
testcase_04 RE -
testcase_05 AC 342 ms
77,184 KB
testcase_06 AC 207 ms
77,056 KB
testcase_07 AC 204 ms
77,312 KB
testcase_08 AC 205 ms
77,056 KB
testcase_09 AC 495 ms
76,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isPrimeMR(n):
    if n in {2, 3, 5, 7, 11, 13, 17}:
        return True
    d = n - 1
    d = d // (d & -d)
    L = (
        [2, 7, 61]
        if n < 1 << 32
        else [2, 3, 5, 7, 11, 13, 17]
        if n < 1 << 48
        else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    )
    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 False
            t <<= 1
    return True


for i in range(int(input())):
  x = int(input())
  print(x, int(isPrimeMR(x)))
0