結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー 遭難者遭難者
提出日時 2023-08-21 21:48:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 415 ms / 9,973 ms
コード長 632 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 78,788 KB
最終ジャッジ日時 2023-08-21 21:48:47
合計ジャッジ時間 3,163 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,080 KB
testcase_01 AC 73 ms
71,132 KB
testcase_02 AC 73 ms
71,216 KB
testcase_03 AC 74 ms
71,228 KB
testcase_04 AC 312 ms
78,124 KB
testcase_05 AC 308 ms
78,044 KB
testcase_06 AC 209 ms
78,084 KB
testcase_07 AC 216 ms
78,284 KB
testcase_08 AC 210 ms
78,008 KB
testcase_09 AC 415 ms
78,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_prime(x) -> bool:
    if x == 2:
        return True
    if x < 2 or (x & 1) == 0:
        return False
    for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
        if a % x == 0:
            continue
        d = x - 1
        s = 0
        while (d & 1) == 0:
            d >>= 1
            s += 1
        t = pow(a, d, x)
        if t == 1:
            continue
        for _ in range(s):
            if t == x - 1:
                break
            t = pow(t, 2, x)
        else:
            return False
    return True
for i in range(int(input())):
    x = int(input())
    print(x, 1 if is_prime(x) else 0)
0