結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー rin204rin204
提出日時 2022-01-25 20:09:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 391 ms / 9,973 ms
コード長 700 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-04-28 09:48:47
合計ジャッジ時間 2,470 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,352 KB
testcase_01 AC 38 ms
51,712 KB
testcase_02 AC 39 ms
51,840 KB
testcase_03 AC 39 ms
51,968 KB
testcase_04 AC 286 ms
76,928 KB
testcase_05 AC 282 ms
77,312 KB
testcase_06 AC 201 ms
76,384 KB
testcase_07 AC 191 ms
76,680 KB
testcase_08 AC 196 ms
76,544 KB
testcase_09 AC 391 ms
76,848 KB
権限があれば一括ダウンロードができます

ソースコード

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())
for _ in range(n):
    a = int(input())
    if isprime(a):
        print(a, 1)
    else:
        print(a, 0)
0