結果

問題 No.8030 ミラー・ラビン素数判定法のテスト
ユーザー akasia_midori
提出日時 2022-05-03 08:04:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 78,520 KB
最終ジャッジ日時 2024-07-02 11:30:24
合計ジャッジ時間 2,717 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import random
def Miller_Rabin_test(num):
    if num == 2:
        return True
    if num > 2 and num & 1 == 0:
        return False

    s, t = 0, num-1
    while t & 1 == 0:
        s, t = s+1, t >> 1
    a = random.randint(1, num-1)
    if pow(a, t, num) == 1:
        return True
    for i in range(0, s):
        if pow(a, pow(2, i) * t, num) == num-1:
            return True
    return False


input_count = 0
N = int(input())
for i in range(N):
    num = int(input())
    if num == 1:
        print(*[1,0])
    else:
        check = Miller_Rabin_test(num)
        ch = 1 if check else 0
        print(*[num, ch])
0