結果

問題 No.6 使いものにならないハッシュ
ユーザー ntuda
提出日時 2024-02-25 22:33:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 878 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 104,900 KB
最終ジャッジ日時 2024-09-29 11:24:23
合計ジャッジ時間 4,327 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

def seachPrimeNum(N):
    if N == 2:
        return []
    max = int(N ** 0.5)
    seachList = [i for i in range(2, N + 1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

from bisect import bisect_left
K = int(input())
N = int(input())
PL = seachPrimeNum(N)
k = bisect_left(PL, K)
X = [-1] * 10

def f(x):
    while x >= 10:
        ret = 0
        while x > 0:
            ret += x % 10
            x //= 10
        x = ret
    return x

n = len(PL)
i = n - 1
tmp2 = 0
tmp = n - 1
ans = 2
while i >= k:
    h = f(PL[i])
    if X[h] != -1:
        if tmp >= X[h]:
            tmp = X[h] - 1
    X[h] = i
    if tmp2 < tmp - i + 1:
        tmp2 = tmp - i + 1
        ans = PL[i]
    i -= 1
print(ans)
0