結果
| 問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
| ユーザー |
iorion
|
| 提出日時 | 2022-02-25 06:44:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 561 ms / 9,973 ms |
| コード長 | 728 bytes |
| コンパイル時間 | 410 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 77,312 KB |
| 最終ジャッジ日時 | 2024-11-16 23:46:39 |
| 合計ジャッジ時間 | 3,084 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
def miller_rabin(n: int) -> bool:
if n <= 2:
return n == 2
if n % 2 == 0:
return False
s = 0
t = n - 1
while t % 2 == 0:
s += 1
t //= 2
def witness_composite(a: int) -> bool:
x = pow(a, t, n)
if x == 1 or x == n - 1:
return False
for _ in range(s - 1):
x = pow(x, 2, n)
if x == n - 1:
return False
return True
for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:
if a >= n:
break
if witness_composite(a):
return False
return True
n = int(input())
for _ in range(n):
x = int(input())
print(x, int(miller_rabin(x)))
iorion