結果

問題 No.6 使いものにならないハッシュ
ユーザー nisizawanisizawa
提出日時 2017-12-19 15:21:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 380 ms / 5,000 ms
コード長 780 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 13,424 KB
最終ジャッジ日時 2023-10-14 23:09:59
合計ジャッジ時間 7,054 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,892 KB
testcase_01 AC 18 ms
9,020 KB
testcase_02 AC 380 ms
13,424 KB
testcase_03 AC 50 ms
9,652 KB
testcase_04 AC 70 ms
9,768 KB
testcase_05 AC 88 ms
10,236 KB
testcase_06 AC 173 ms
11,132 KB
testcase_07 AC 98 ms
10,096 KB
testcase_08 AC 154 ms
10,836 KB
testcase_09 AC 65 ms
9,560 KB
testcase_10 AC 20 ms
8,964 KB
testcase_11 AC 56 ms
9,768 KB
testcase_12 AC 227 ms
12,036 KB
testcase_13 AC 46 ms
9,144 KB
testcase_14 AC 65 ms
9,476 KB
testcase_15 AC 180 ms
11,160 KB
testcase_16 AC 118 ms
10,404 KB
testcase_17 AC 256 ms
11,976 KB
testcase_18 AC 359 ms
13,128 KB
testcase_19 AC 245 ms
11,980 KB
testcase_20 AC 214 ms
11,796 KB
testcase_21 AC 37 ms
9,336 KB
testcase_22 AC 226 ms
11,688 KB
testcase_23 AC 209 ms
11,828 KB
testcase_24 AC 222 ms
11,652 KB
testcase_25 AC 117 ms
10,392 KB
testcase_26 AC 276 ms
12,296 KB
testcase_27 AC 192 ms
11,320 KB
testcase_28 AC 116 ms
10,608 KB
testcase_29 AC 297 ms
12,608 KB
testcase_30 AC 254 ms
12,244 KB
testcase_31 AC 222 ms
11,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache

def prime_ls(k, n):
    ls = [i for i in range(max(2, k), n + 1) if i == 2 or not i % 2 == 0]
    for i in range(3, int(n**0.5) + 1, 2):
        ls = [j for j in ls if j == i or not j % i == 0]
    return ls

@lru_cache(maxsize=None)
def hash(n):
    if n // 10 == 0:
        return n
    s = str(n)
    return hash(sum([int(c) for c in s]))

k = int(input())
n = int(input())

p_ls = prime_ls(k, n)
h_ls = [hash(p) for p in p_ls]

l, r = 0, 0
max_len = 0

memo = [False] * 10

while r < len(h_ls):
    hl = h_ls[l]
    hr = h_ls[r]
    if memo[hr]:
        memo[hl] = False
        l += 1
    else:
        memo[hr] = True
        r += 1
    
    lr_len = r - l
    if lr_len >= max_len:
        max_len = lr_len
        ans = p_ls[l]

print(ans)
0