結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー akasia_midoriakasia_midori
提出日時 2022-05-03 08:04:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 80,868 KB
最終ジャッジ日時 2023-09-15 06:59:15
合計ジャッジ時間 3,390 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
72,236 KB
testcase_01 AC 90 ms
72,156 KB
testcase_02 AC 92 ms
72,148 KB
testcase_03 AC 94 ms
72,132 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

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