結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー GrayCoderGrayCoder
提出日時 2018-11-11 10:05:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 657 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 10,756 KB
実行使用メモリ 18,744 KB
最終ジャッジ日時 2023-08-11 22:09:10
合計ジャッジ時間 11,835 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import random
from sys import stdin, stdout

def main():
    N = int(input())
    X = map(int, stdin.read().splitlines())

    for i in X:
        stdout.write(str(i) + ' ' + is_prime(i) + '\n')

def is_prime(n):
    if n == 2: return '1'
    if n == 1 or not n % 2: return '0'

    d = (n - 1) >> 1
    while not d % 2:
        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 not t % 2:
            return '0'
    return '1'

input = lambda: stdin.readline()
main()
0