結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
👑 |
| 提出日時 | 2022-08-26 18:37:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 380 ms / 9,973 ms |
| コード長 | 676 bytes |
| コンパイル時間 | 440 ms |
| コンパイル使用メモリ | 82,228 KB |
| 実行使用メモリ | 77,312 KB |
| 最終ジャッジ日時 | 2024-11-16 23:57:41 |
| 合計ジャッジ時間 | 2,571 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
def miller_rabin(x: int):
if x == 2:
return 1
if x < 2 or (x & 1) == 0:
return 0
for a in [2,325,9375,28178,450775,9780504,1795265022]:
if a % x == 0:
continue
d = x - 1
s = 0
while (d & 1) == 0:
d //= 2
s += 1
t = pow(a, d, x)
if t == 1:
continue
for _ in range(s):
if t == (x - 1):
break
t = pow(t, 2, x)
else: # breakでループを抜けなかった時
return 0
continue
return 1
n = int(input())
for _ in range(n):
x = int(input())
print(x,miller_rabin(x))