結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー GrayCoderGrayCoder
提出日時 2018-11-11 10:10:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 656 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 9,936 KB
最終ジャッジ日時 2023-08-11 22:08:35
合計ジャッジ時間 22,310 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,708 KB
testcase_01 AC 19 ms
8,716 KB
testcase_02 AC 20 ms
8,720 KB
testcase_03 AC 21 ms
8,716 KB
testcase_04 AC 5,064 ms
9,820 KB
testcase_05 AC 4,526 ms
9,936 KB
testcase_06 AC 319 ms
9,820 KB
testcase_07 AC 313 ms
9,908 KB
testcase_08 AC 315 ms
9,888 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます

ソースコード

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(50):
        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