結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
ゆるく
|
| 提出日時 | 2014-10-11 01:05:28 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 847 ms / 5,000 ms |
| コード長 | 915 bytes |
| コンパイル時間 | 147 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 13,824 KB |
| 最終ジャッジ日時 | 2024-09-16 16:21:30 |
| 合計ジャッジ時間 | 13,536 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
import heapq
from collections import deque
import re
def is_prime(n):
i = 2
while i * i <=n:
if n % i == 0:
return False
i += 1
return True
def sp(n):
v = str(n)
while v:
s = 0
for vv in v:
s += int(vv)
if s < 10:
return int(s)
v = str(s)
K = int(input())
N = int(input())
if K == 1:
K += 1
a = []
b = []
mx = []
box = deque()
start = 0
end = 0
for i in range(K, N + 1):
if is_prime(i):
t = sp(i)
a.append(i)
b.append(t)
while (start <= end < len(b)):
if not (b[end] in box):
box.append(b[end])
end += 1
else:
heapq.heappush(mx, [-(len(box)), -(a[start])])
box.clear()
start += 1
end = start
heapq.heappush(mx, [-(len(box)), -(a[start])])
print(-(heapq.heappop(mx)[1]))
ゆるく