結果

問題 No.6 使いものにならないハッシュ
ユーザー roarisroaris
提出日時 2019-10-27 20:20:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 907 bytes
コンパイル時間 2,635 ms
コンパイル使用メモリ 86,268 KB
実行使用メモリ 80,316 KB
最終ジャッジ日時 2023-10-14 23:20:23
合計ジャッジ時間 5,972 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,912 KB
testcase_01 AC 91 ms
72,008 KB
testcase_02 AC 130 ms
80,316 KB
testcase_03 AC 121 ms
78,364 KB
testcase_04 AC 121 ms
78,624 KB
testcase_05 AC 128 ms
78,956 KB
testcase_06 AC 132 ms
79,596 KB
testcase_07 AC 121 ms
78,936 KB
testcase_08 AC 125 ms
79,392 KB
testcase_09 AC 123 ms
79,488 KB
testcase_10 AC 93 ms
71,496 KB
testcase_11 AC 120 ms
78,252 KB
testcase_12 AC 131 ms
79,504 KB
testcase_13 AC 115 ms
79,516 KB
testcase_14 AC 120 ms
79,484 KB
testcase_15 AC 126 ms
79,376 KB
testcase_16 AC 124 ms
79,468 KB
testcase_17 AC 132 ms
80,084 KB
testcase_18 AC 137 ms
80,280 KB
testcase_19 AC 137 ms
79,944 KB
testcase_20 AC 135 ms
79,952 KB
testcase_21 AC 123 ms
78,048 KB
testcase_22 AC 128 ms
79,916 KB
testcase_23 AC 125 ms
79,440 KB
testcase_24 AC 127 ms
79,652 KB
testcase_25 AC 127 ms
78,976 KB
testcase_26 AC 131 ms
80,028 KB
testcase_27 AC 127 ms
79,736 KB
testcase_28 AC 123 ms
78,620 KB
testcase_29 AC 131 ms
80,076 KB
testcase_30 AC 130 ms
79,644 KB
testcase_31 AC 125 ms
79,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def era(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        
        for j in range(2*i, n+1, i):
            is_prime[j] = False
    
    return [i for i in range(K, n+1) if is_prime[i]]
    
def calc(n):
    if len(str(n)) == 1:
        return n
    
    s = 0
    
    for ni in str(n):
        s += int(ni)
    
    return calc(s)

K = int(input())
N = int(input())
primes = era(N)
hashed = [calc(p) for p in primes]

r = 0
length = 0
d = defaultdict(int)

for l in range(len(hashed)):
    while r < len(hashed) and d[hashed[r]] == 0:
        d[hashed[r]] += 1
        r += 1
    
    if length <= r-l:
        length = r-l
        ans = primes[l]
        
    if l == r:
        r += 1
    
    d[hashed[l]] -= 1
    l += 1

print(ans)
0