結果
問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
ユーザー |
![]() |
提出日時 | 2020-11-11 00:07:44 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 724 bytes |
コンパイル時間 | 248 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-11-18 18:37:09 |
合計ジャッジ時間 | 5,742 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 WA * 1 |
ソースコード
def miller_rabin(n): if n < 2: return False for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]: if n < p * p: return True if n % p == 0: return False s, d = 0, n - 1 while d & 1 == 0: s, d = s + 1, d >> 1 # n = (2 ** s) * d 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)