結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー kemunikukemuniku
提出日時 2022-09-24 04:34:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 368 ms / 9,973 ms
コード長 735 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,268 KB
実行使用メモリ 77,808 KB
最終ジャッジ日時 2024-06-01 18:42:20
合計ジャッジ時間 2,358 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,096 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 39 ms
52,352 KB
testcase_04 AC 262 ms
77,804 KB
testcase_05 AC 259 ms
77,808 KB
testcase_06 AC 165 ms
77,440 KB
testcase_07 AC 164 ms
77,236 KB
testcase_08 AC 161 ms
77,496 KB
testcase_09 AC 368 ms
77,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isprime(N):
    bases = [2,325,9375,28178,450775,9780504,1795265022]
    if N < 2:
        return False
    if N == 2:
        return True
    if N%2 == 0:
        return False
    N1 = N-1
    s,d = (N1 & -N1).bit_length()-1,N1//(N1 & -N1)
    for b in bases:
        if b % N == 0:
            continue
        t = pow(b,d,N)
        if t == 1 or t == N1:
            continue
        for _ in range(s-1):
            t = pow(t,2,N)
            if t == N1:
                break
        else:
            return False
    return True
import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
N = int(input())
for i in range(N):
    X =int(input())
    if isprime(X):
        print(X,1)
    else:
        print(X,0)
0