結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
|
| 提出日時 | 2022-08-24 18:40:54 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 821 bytes |
| コンパイル時間 | 145 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 21,632 KB |
| 最終ジャッジ日時 | 2024-10-12 03:11:36 |
| 合計ジャッジ時間 | 12,040 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 5 |
ソースコード
def miller_rabin(n, bases):
d, s = n - 1, 0
while d % 2 == 0:
d >>= 1
s += 1
for a in bases:
if n <= a:
return True
a = pow(a, d, n)
if a == 1:
continue
r = 1
while a != n - 1:
if r == s:
return False
a = a * a % n
r += 1
return True
def is_prime1(n):
# < 4759123141
return miller_rabin(n, [2, 7, 61])
def is_prime2(n):
# < 2 ** 64
return miller_rabin(n, [2, 325, 9375, 28178, 450775, 9780504, 1795265022])
def is_prime(n):
"""
https://miller-rabin.appspot.com/
"""
if n < 4759123141:
return is_prime1(n)
else:
return is_prime2(n)
for i in range(int(input())):
x = int(input())
print(x, int(is_prime(x)))