結果

問題 No.6 使いものにならないハッシュ
ユーザー otsunekootsuneko
提出日時 2021-04-27 13:20:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 1,028 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 78,980 KB
最終ジャッジ日時 2023-09-20 11:52:57
合計ジャッジ時間 6,315 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,288 KB
testcase_01 AC 75 ms
71,168 KB
testcase_02 AC 128 ms
78,980 KB
testcase_03 AC 111 ms
77,636 KB
testcase_04 AC 109 ms
77,388 KB
testcase_05 AC 117 ms
77,208 KB
testcase_06 AC 118 ms
77,792 KB
testcase_07 AC 117 ms
77,824 KB
testcase_08 AC 119 ms
78,084 KB
testcase_09 AC 116 ms
78,684 KB
testcase_10 AC 75 ms
71,068 KB
testcase_11 AC 111 ms
77,544 KB
testcase_12 AC 126 ms
77,956 KB
testcase_13 AC 110 ms
78,464 KB
testcase_14 AC 114 ms
78,552 KB
testcase_15 AC 122 ms
77,888 KB
testcase_16 AC 119 ms
78,440 KB
testcase_17 AC 123 ms
78,936 KB
testcase_18 AC 132 ms
78,656 KB
testcase_19 AC 130 ms
78,436 KB
testcase_20 AC 126 ms
78,172 KB
testcase_21 AC 109 ms
77,652 KB
testcase_22 AC 130 ms
78,160 KB
testcase_23 AC 121 ms
78,260 KB
testcase_24 AC 132 ms
78,236 KB
testcase_25 AC 117 ms
77,904 KB
testcase_26 AC 126 ms
78,348 KB
testcase_27 AC 134 ms
78,332 KB
testcase_28 AC 119 ms
77,692 KB
testcase_29 AC 126 ms
78,668 KB
testcase_30 AC 123 ms
78,056 KB
testcase_31 AC 125 ms
78,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, n+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    table = [ i-1 for i in range(1, n+1) if is_prime[i-1]] # 素数のリスト
    return table

def digsum(n):
    res = 0
    while n > 0:
        res += n%10
        n //= 10
    
    return res

K = int(input())
N = int(input())

prime = sieve(N+1)
idx = bisect.bisect_left(prime, K)

hash = []
for i in range(idx,len(prime)):
    n = digsum(prime[i])
    while len(str(n)) > 1:
        n = digsum(n)
    hash.append(n)

length = len(hash)
r, ans, max_len = 0, 0, 0
for l in range(length):
    while r < length and len(hash[l:r]) == len(set(hash[l:r])):
        r += 1
    if len(set(hash[l:r])) >= max_len:
        ans = prime[idx+l]
        max_len = len(set(hash[l:r]))
    if l == r:
        r += 1
print(ans)
0