結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー aqua_tenhouaqua_tenhou
提出日時 2020-09-15 21:04:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,517 ms / 9,973 ms
コード長 569 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 78,392 KB
最終ジャッジ日時 2024-04-28 09:36:23
合計ジャッジ時間 8,495 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,888 KB
testcase_01 AC 38 ms
53,888 KB
testcase_02 AC 39 ms
54,144 KB
testcase_03 AC 39 ms
54,528 KB
testcase_04 AC 1,794 ms
78,392 KB
testcase_05 AC 1,651 ms
77,952 KB
testcase_06 AC 208 ms
78,080 KB
testcase_07 AC 208 ms
77,824 KB
testcase_08 AC 225 ms
77,696 KB
testcase_09 AC 3,517 ms
78,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)

        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False

    return True

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