結果

問題 No.6 使いものにならないハッシュ
ユーザー nisizawanisizawa
提出日時 2017-12-19 15:55:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 902 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 12,824 KB
最終ジャッジ日時 2023-08-22 19:33:18
合計ジャッジ時間 4,849 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 22 ms
8,848 KB
testcase_02 AC 129 ms
12,824 KB
testcase_03 AC 38 ms
9,336 KB
testcase_04 AC 47 ms
10,024 KB
testcase_05 AC 52 ms
9,796 KB
testcase_06 AC 79 ms
11,076 KB
testcase_07 AC 61 ms
10,332 KB
testcase_08 AC 78 ms
10,784 KB
testcase_09 AC 64 ms
10,724 KB
testcase_10 RE -
testcase_11 AC 39 ms
9,568 KB
testcase_12 AC 90 ms
11,316 KB
testcase_13 AC 57 ms
10,032 KB
testcase_14 AC 62 ms
10,608 KB
testcase_15 AC 77 ms
10,832 KB
testcase_16 AC 72 ms
10,964 KB
testcase_17 AC 101 ms
11,960 KB
testcase_18 AC 122 ms
12,448 KB
testcase_19 AC 99 ms
11,668 KB
testcase_20 AC 87 ms
11,456 KB
testcase_21 AC 30 ms
9,120 KB
testcase_22 AC 93 ms
11,664 KB
testcase_23 AC 87 ms
11,480 KB
testcase_24 AC 89 ms
11,364 KB
testcase_25 AC 65 ms
10,460 KB
testcase_26 AC 105 ms
11,900 KB
testcase_27 AC 87 ms
11,392 KB
testcase_28 AC 62 ms
10,372 KB
testcase_29 AC 112 ms
12,108 KB
testcase_30 AC 100 ms
11,508 KB
testcase_31 AC 92 ms
11,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache

def prime_ls(k, n):
    ls = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(n)]
    ls[0] = ls[1] = False
    ls[2] = ls[3] = ls[5] = True

    for i in range(3, int(n**0.5) + 1, 2):
        for j in range(i**2, n, i): 
            ls[j] = False
    
    return [p for p, is_prime in enumerate(ls[k:], k) if is_prime]

@lru_cache(maxsize=None)
def hash(n):
    s = str(n)
    return hash(sum([int(c) for c in s])) if len(s) >= 2 else n

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, hr = h_ls[l], 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