結果

問題 No.6 使いものにならないハッシュ
ユーザー ゆるくゆるく
提出日時 2014-10-11 01:05:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 743 ms / 5,000 ms
コード長 915 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2023-10-14 22:46:15
合計ジャッジ時間 12,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
9,180 KB
testcase_01 AC 27 ms
9,140 KB
testcase_02 AC 743 ms
12,160 KB
testcase_03 AC 91 ms
9,760 KB
testcase_04 AC 143 ms
9,740 KB
testcase_05 AC 162 ms
10,276 KB
testcase_06 AC 376 ms
10,720 KB
testcase_07 AC 217 ms
10,044 KB
testcase_08 AC 333 ms
10,472 KB
testcase_09 AC 145 ms
9,632 KB
testcase_10 AC 26 ms
9,248 KB
testcase_11 AC 99 ms
9,748 KB
testcase_12 AC 433 ms
11,300 KB
testcase_13 AC 91 ms
9,484 KB
testcase_14 AC 144 ms
9,548 KB
testcase_15 AC 347 ms
10,784 KB
testcase_16 AC 269 ms
10,108 KB
testcase_17 AC 562 ms
11,116 KB
testcase_18 AC 697 ms
11,968 KB
testcase_19 AC 530 ms
11,108 KB
testcase_20 AC 446 ms
10,896 KB
testcase_21 AC 61 ms
9,508 KB
testcase_22 AC 498 ms
11,028 KB
testcase_23 AC 431 ms
10,980 KB
testcase_24 AC 463 ms
10,892 KB
testcase_25 AC 255 ms
10,140 KB
testcase_26 AC 587 ms
11,468 KB
testcase_27 AC 435 ms
10,744 KB
testcase_28 AC 245 ms
10,408 KB
testcase_29 AC 621 ms
11,472 KB
testcase_30 AC 523 ms
11,476 KB
testcase_31 AC 484 ms
11,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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