結果

問題 No.6 使いものにならないハッシュ
ユーザー szkhtsszkhts
提出日時 2022-02-27 13:25:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 727 ms / 5,000 ms
コード長 904 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 12,280 KB
最終ジャッジ日時 2023-09-18 23:53:21
合計ジャッジ時間 12,164 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
9,148 KB
testcase_01 AC 26 ms
9,312 KB
testcase_02 AC 727 ms
12,280 KB
testcase_03 AC 90 ms
9,832 KB
testcase_04 AC 142 ms
9,960 KB
testcase_05 AC 162 ms
10,340 KB
testcase_06 AC 371 ms
10,700 KB
testcase_07 AC 217 ms
10,104 KB
testcase_08 AC 330 ms
10,476 KB
testcase_09 AC 144 ms
9,508 KB
testcase_10 AC 26 ms
9,244 KB
testcase_11 AC 97 ms
9,876 KB
testcase_12 AC 433 ms
11,264 KB
testcase_13 AC 91 ms
9,388 KB
testcase_14 AC 143 ms
9,672 KB
testcase_15 AC 341 ms
10,788 KB
testcase_16 AC 269 ms
10,072 KB
testcase_17 AC 557 ms
11,048 KB
testcase_18 AC 700 ms
12,048 KB
testcase_19 AC 532 ms
10,944 KB
testcase_20 AC 444 ms
11,020 KB
testcase_21 AC 60 ms
9,580 KB
testcase_22 AC 493 ms
10,988 KB
testcase_23 AC 429 ms
11,040 KB
testcase_24 AC 459 ms
10,912 KB
testcase_25 AC 253 ms
10,204 KB
testcase_26 AC 585 ms
11,472 KB
testcase_27 AC 440 ms
10,700 KB
testcase_28 AC 241 ms
10,416 KB
testcase_29 AC 616 ms
11,456 KB
testcase_30 AC 521 ms
11,392 KB
testcase_31 AC 474 ms
10,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
from collections import deque
import re

def is_prime(p):
    i = 2
    while (i * i) <= p:
        if p % i == 0:
            return False
        i += 1
    return True

def sp(p):
    v = str(p)
    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())
primes = []
hashes = []

if K < 2:
    K = 2

for i in range(K, N + 1):
    if is_prime(i):
        primes.append(i)
        hashes.append(sp(i))

start = 0
end = 0
coll = deque()
mx = []
while(start <= end < len(hashes)):
    if hashes[end] not in coll:
        coll.append(hashes[end])
        end += 1
    else:
        heapq.heappush(mx, [-(len(coll)), -(primes[start])])
        coll.clear()
        start += 1
        end = start

heapq.heappush(mx, [-(len(coll)), -(primes[start])])
print(-(heapq.heappop(mx)[1]))
0