結果

問題 No.6 使いものにならないハッシュ
コンテスト
ユーザー irumo8202
提出日時 2022-01-24 16:35:02
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 265 ms / 5,000 ms
コード長 814 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,195 ms
コンパイル使用メモリ 20,696 KB
実行使用メモリ 16,604 KB
最終ジャッジ日時 2026-05-25 07:40:36
合計ジャッジ時間 7,589 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque


def list_primes(limit):
    primes = []
    is_prime = [True] * (limit + 1)
    is_prime[0] = False
    is_prime[1] = False

    for p in range(0, limit + 1):
        if not is_prime[p]:
            continue
        primes.append(p)
        for i in range(p * p, limit + 1, p):
            is_prime[i] = False

    return primes


def digits_sum(num):
    res = str(num)
    while len(res) != 1:
        res = sum(int(x) for x in res)
        res = str(res)
    return res


K = int(input())
N = int(input())
mx = 0
used = deque()
ans = 2
for p in list_primes(N)[::-1]:
    if p < K:
        break
    x = digits_sum(p)
    if x in used:
        while x != used.popleft():
            pass
    used.append(x)
    if len(used) > mx:
        mx = len(used)
        ans = p

print(ans)
0