結果
問題 | No.3030 ミラー・ラビン素数判定法のテスト |
ユーザー | hiro1729 |
提出日時 | 2023-12-21 20:47:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 376 ms / 9,973 ms |
コード長 | 486 bytes |
コンパイル時間 | 141 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 76,648 KB |
最終ジャッジ日時 | 2023-12-21 20:47:30 |
合計ジャッジ時間 | 2,401 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
53,460 KB |
testcase_01 | AC | 36 ms
53,460 KB |
testcase_02 | AC | 36 ms
53,460 KB |
testcase_03 | AC | 36 ms
53,460 KB |
testcase_04 | AC | 267 ms
76,252 KB |
testcase_05 | AC | 271 ms
76,412 KB |
testcase_06 | AC | 182 ms
76,648 KB |
testcase_07 | AC | 183 ms
76,644 KB |
testcase_08 | AC | 186 ms
76,512 KB |
testcase_09 | AC | 376 ms
76,288 KB |
ソースコード
# N≦2^64 def is_prime(N: int): if N <= 1: return False if N == 2: return True if N % 2 == 0: return False s = 0 d = N - 1 while d % 2 == 0: s += 1 d >>= 1 for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: if a % N == 0: return True x = pow(a, d, N) if x != 1: t = 0 while t < s and x < N - 1: t += 1 x = x * x % N if t == s: return False return True for _ in range(int(input())): n = int(input()) print(n, is_prime(n) | 0)