結果

問題 No.8030 ミラー・ラビン素数判定法のテスト
ユーザー 遭難者
提出日時 2023-08-21 21:48:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 347 ms / 9,973 ms
コード長 632 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 77,400 KB
最終ジャッジ日時 2024-12-15 13:18:24
合計ジャッジ時間 2,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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