結果
問題 |
No.308 素数は通れません
|
ユーザー |
|
提出日時 | 2015-12-05 10:42:42 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 903 bytes |
コンパイル時間 | 244 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-09-14 14:23:11 |
合計ジャッジ時間 | 6,064 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 87 WA * 20 |
ソースコード
import random def MillerRabin(q, k = 50): ''' 素数判定の ミラー・ラビン テスト 以下のコードをもとに作成。 http://d.hatena.ne.jp/pashango_p/20090704/1246692091 ''' if q == 2: return True if q == 1 or not (q & 1): return False d = (q - 1) >> 1 while not (d & 1): d >>= 1 for i in range(k): a = random.randint(1, q - 1) t = d y = pow(a, t, q) while t != q - 1 and y != 1 and y != q - 1: y = pow(y, 2, q) t <<= 1 if y != q - 1 and not (t & 1): return False return True def solve(N): dic = {4:3, 6:5, 8:7, 9:7, 10:7, 12:11, 14:13, 15:7, 16:7, 18:8, 20:19, 21:19, 22:7, 24:23, 25:23, 26:8} if N in dic: return dic[N] M = N - 8 if MillerRabin(M): return 14 return 8 N = int(input()) print(solve(N))