結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー ShirotsumeShirotsume
提出日時 2021-11-05 17:57:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,664 ms / 9,973 ms
コード長 547 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 79,280 KB
最終ジャッジ日時 2024-04-28 09:47:44
合計ジャッジ時間 8,619 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,388 KB
testcase_01 AC 39 ms
55,292 KB
testcase_02 AC 44 ms
55,972 KB
testcase_03 AC 39 ms
56,504 KB
testcase_04 AC 1,821 ms
79,280 KB
testcase_05 AC 1,649 ms
78,720 KB
testcase_06 AC 218 ms
78,464 KB
testcase_07 AC 214 ms
78,372 KB
testcase_08 AC 223 ms
78,216 KB
testcase_09 AC 3,664 ms
78,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import random
from collections import defaultdict
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

t = int(input())

for _ in range(t):
    x = int(input())
    print(x, int(is_prime(x)))
0