結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー trineutrontrineutron
提出日時 2020-11-25 20:04:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 647 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-29 14:39:06
合計ジャッジ時間 12,183 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
11,264 KB
testcase_01 AC 27 ms
11,136 KB
testcase_02 AC 30 ms
11,136 KB
testcase_03 AC 33 ms
11,008 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import randrange

def odd(n):
    while n % 2 == 0:
        n //= 2
    return n

def prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    for i in range(1000):
        a = randrange(2, n)
        if pow(a, n - 1, n) != 1:
            return False
        prev = pow(a, odd(n - 1), n)
        if prev == 0:
            continue
        while prev * prev % n != 1:
            prev *= prev
            prev %= n
        if prev != n - 1:
            return False
    return True

n = int(input())
for i in range(n):
    x = int(input())
    if prime(x):
        print(x, 1)
    else:
        print(x, 0)
0