結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー 👑 rin204rin204
提出日時 2022-01-25 20:09:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 709 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 53,748 KB
最終ジャッジ日時 2024-05-09 21:16:20
合計ジャッジ時間 1,583 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def isprime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1
    
    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True
        

n = int(input())
A = list(map(int, input().split()))
for a in A:
    if isprime(a):
        print("Yes")
    else:
        print("No")
0