結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー trineutrontrineutron
提出日時 2020-11-25 20:09:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 4,081 ms / 9,973 ms
コード長 684 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 8,892 KB
最終ジャッジ日時 2023-08-10 16:26:34
合計ジャッジ時間 10,769 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,816 KB
testcase_01 AC 18 ms
8,764 KB
testcase_02 AC 18 ms
8,764 KB
testcase_03 AC 18 ms
8,764 KB
testcase_04 AC 2,063 ms
8,892 KB
testcase_05 AC 1,942 ms
8,784 KB
testcase_06 AC 425 ms
8,784 KB
testcase_07 AC 443 ms
8,784 KB
testcase_08 AC 441 ms
8,788 KB
testcase_09 AC 4,081 ms
8,712 KB
権限があれば一括ダウンロードができます

ソースコード

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
    if n == 3:
        return True
    for i in range(10):
        a = randrange(2, n - 1)
        if pow(a, n - 1, n) != 1:
            return False
        prev = pow(a, odd(n - 1), n)
        if prev == 1:
            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