結果

問題 No.3030 ミラー・ラビン素数判定法のテスト
ユーザー masa_aamasa_aa
提出日時 2020-09-21 01:30:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 688 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 87,360 KB
実行使用メモリ 78,308 KB
最終ジャッジ日時 2023-08-11 23:09:46
合計ジャッジ時間 3,724 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,496 KB
testcase_01 AC 67 ms
71,412 KB
testcase_02 AC 66 ms
71,596 KB
testcase_03 AC 67 ms
71,468 KB
testcase_04 WA -
testcase_05 AC 386 ms
78,232 KB
testcase_06 AC 264 ms
77,996 KB
testcase_07 AC 263 ms
77,920 KB
testcase_08 AC 263 ms
77,740 KB
testcase_09 AC 553 ms
78,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# v = [2, 7, 61]
# # N <= 4,759,123,140 (4*10^9)
v = [2, 3, 5, 7, 11, 13]
# N <= n < 341,550,071,728,321 (3*10^14)


def Miller(N):
    if N < 2:
        return 0
    d = N - 1
    s = 0
    while d % 2 == 0:
        d //= 2
        s += 1

    for a in v:
        if a == N:
            return 1
        if pow(a, d, N) != 1:
            ok = True
            for r in range(s):
                if pow(a, d * 1 << r, N) == N - 1:
                    ok = 0
                    break
            if ok:
                return 0
    return 1


import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
for _ in range(int(input())):
    n = int(input())
    print(n, Miller(n))
0