結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー Dr_GeometryDr_Geometry
提出日時 2020-07-25 17:32:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,688 ms / 9,973 ms
コード長 645 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-28 09:32:11
合計ジャッジ時間 7,884 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
11,008 KB
testcase_01 AC 34 ms
11,008 KB
testcase_02 AC 34 ms
11,136 KB
testcase_03 AC 34 ms
11,008 KB
testcase_04 AC 1,470 ms
11,008 KB
testcase_05 AC 1,373 ms
11,008 KB
testcase_06 AC 435 ms
11,136 KB
testcase_07 AC 442 ms
11,136 KB
testcase_08 AC 440 ms
11,136 KB
testcase_09 AC 2,688 ms
11,264 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(10):
        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

if __name__ == '__main__':
    n = int(input())
    for i in range(n):
        x = int(input())
        if(is_prime(x)):
            print(str(x) + " 1")
        else:
            print(str(x) + " 0")
0