結果

問題 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
コンパイル時間 171 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 18,972 KB
最終ジャッジ日時 2024-04-29 13:06:43
合計ジャッジ時間 24,620 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
11,008 KB
testcase_01 AC 34 ms
11,008 KB
testcase_02 AC 33 ms
11,136 KB
testcase_03 AC 35 ms
11,136 KB
testcase_04 AC 6,106 ms
11,776 KB
testcase_05 AC 5,379 ms
12,032 KB
testcase_06 AC 387 ms
11,844 KB
testcase_07 AC 380 ms
11,972 KB
testcase_08 AC 372 ms
11,972 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