結果
問題 |
No.8030 ミラー・ラビン素数判定法のテスト
|
ユーザー |
|
提出日時 | 2020-09-05 04:04:01 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 780 bytes |
コンパイル時間 | 1,177 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-11-18 18:18:34 |
合計ジャッジ時間 | 1,154 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 10 |
ソースコード
def miller_rabin(N): if N <= 1: return False if N == 2: return True M = N-1 cnt = 0 while M % 2 == 0: M //= 2 cnt += 1 v = [] for i in range(10): v.append(random.randint(2,N-1)) for a in v: r = 1 K = M while K > 0: if K%2 == 1: r *= a r %= N K //= 2 a *= a a %= N if r == 1: continue for i in range(cnt): if r == N-1: break r *= r r %= N if r != N-1: 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)