結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

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

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