結果

問題 No.6 使いものにならないハッシュ
ユーザー H3PO4
提出日時 2020-04-17 11:03:45
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 678 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-09-16 16:55:34
合計ジャッジ時間 3,642 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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


def primes(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(i * 2, n + 1, i):
            is_prime[j] = False
    return (i for i in range(n + 1) if is_prime[i])


idx_lst = [None] * 10
P = tuple(filter(lambda x: x >= K, primes(N)))
ans = P[0]
l = 0
M = 0
for r, p in enumerate(P):
    while p >= 10:
        p = sum(int(x) for x in str(p))
    if idx_lst[p] is not None:
        l = max(l, idx_lst[p] + 1)
    idx_lst[p] = r
    if M <= r - l:
        ans = P[l]
        M = r - l
print(ans)
0