結果
| 問題 | No.308 素数は通れません |
| コンテスト | |
| ユーザー |
matsu7874
|
| 提出日時 | 2015-12-28 02:40:34 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 654 bytes |
| 記録 | |
| コンパイル時間 | 121 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-09-19 07:34:06 |
| 合計ジャッジ時間 | 5,329 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 90 WA * 1 RE * 16 |
ソースコード
def miller_rabin_test(n):
if n == 2:
return True
if n < 2 or n & 1 == 0:
return False
d = (n - 1) >> 1
while d & 1 == 0:
d >>= 1
for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]:
t = d
y = pow(a, t, n)
while t != n - 1 and y != 1 and y != n - 1:
y = pow(y, 2, n)
t <<= 1
if y != n - 1 and t & 1 == 0:
return False
return True
N = int(input())
if N <= 26:
print([0,0,0,0,3,0,5,0,7,7,7,0,11,0,13,7,7,0,8,0,19,19,7,0,23,23][i])
else:
if N % 8 == 1 and miller_rabin_test(N - 8):
print(14)
else:
print(8)
matsu7874