結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー GrayCoderGrayCoder
提出日時 2018-11-11 09:55:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 693 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 14,220 KB
最終ジャッジ日時 2023-08-11 22:07:49
合計ジャッジ時間 32,388 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,888 KB
testcase_01 AC 19 ms
8,732 KB
testcase_02 AC 19 ms
8,832 KB
testcase_03 AC 20 ms
8,792 KB
testcase_04 AC 9,949 ms
9,756 KB
testcase_05 AC 8,852 ms
9,780 KB
testcase_06 AC 342 ms
9,892 KB
testcase_07 AC 319 ms
9,820 KB
testcase_08 AC 320 ms
9,892 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) + ' ')
        stdout.write(str(int(is_prime(i))) + '\n')

def is_prime(n):
    if n == 2: return True
    if n == 1 or not n % 2: return False

    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 False
    return True

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