結果

問題 No.6 使いものにならないハッシュ
コンテスト
ユーザー ゆるく
提出日時 2014-10-11 01:05:28
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 575 ms / 5,000 ms
コード長 915 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 357 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 17,112 KB
最終ジャッジ日時 2026-04-05 21:00:41
合計ジャッジ時間 11,106 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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]))
0