結果
問題 | No.8030 ミラー・ラビン素数判定法のテスト |
ユーザー |
![]() |
提出日時 | 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 == 2if n % 2 == 0:return Falses = 0t = n - 1while t % 2 == 0:s += 1t //= 2def witness_composite(a: int) -> bool:x = pow(a, t, n)if x == 1 or x == n - 1:return Falsefor _ in range(s - 1):x = pow(x, 2, n)if x == n - 1:return Falsereturn Truefor a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]:if a >= n:breakif witness_composite(a):return Falsereturn Truen = int(input())for _ in range(n):x = int(input())print(x, int(miller_rabin(x)))