結果
問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
ユーザー |
![]() |
提出日時 | 2020-11-11 00:20:03 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 612 bytes |
コンパイル時間 | 421 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-11-18 18:46:45 |
合計ジャッジ時間 | 5,065 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 WA * 1 |
ソースコード
def miller_rabin(n): if n < 9: return n == 2 or n == 3 or n == 5 or n == 7 if n & 1 == 0: return False d = n - 1 s = (d & -d).bit_length() - 1 d >>= s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: x = pow(a, d, n) if x in (1, n - 1): continue for _ in range(s - 1): x = (x * x) % n if x == n - 1: break else: return False return True n = int(input()) for i in range(n): a = int(input()) b = 0 if miller_rabin(a): b = 1 print(a, b)