結果

問題 No.6 使いものにならないハッシュ
ユーザー rlangevinrlangevin
提出日時 2023-10-02 08:58:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 820 bytes
コンパイル時間 1,421 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 80,788 KB
最終ジャッジ日時 2023-10-02 08:58:15
合計ジャッジ時間 7,114 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,556 KB
testcase_01 AC 93 ms
71,608 KB
testcase_02 AC 137 ms
80,768 KB
testcase_03 AC 119 ms
77,876 KB
testcase_04 AC 119 ms
78,468 KB
testcase_05 AC 134 ms
77,904 KB
testcase_06 AC 132 ms
79,156 KB
testcase_07 AC 123 ms
78,488 KB
testcase_08 AC 131 ms
78,944 KB
testcase_09 AC 131 ms
80,532 KB
testcase_10 AC 98 ms
71,848 KB
testcase_11 AC 124 ms
78,208 KB
testcase_12 AC 134 ms
78,716 KB
testcase_13 AC 127 ms
79,860 KB
testcase_14 AC 126 ms
79,548 KB
testcase_15 AC 131 ms
78,792 KB
testcase_16 AC 134 ms
79,728 KB
testcase_17 AC 136 ms
80,788 KB
testcase_18 AC 139 ms
80,380 KB
testcase_19 AC 142 ms
79,868 KB
testcase_20 AC 135 ms
79,460 KB
testcase_21 AC 124 ms
78,088 KB
testcase_22 AC 140 ms
79,812 KB
testcase_23 AC 135 ms
79,120 KB
testcase_24 AC 136 ms
79,404 KB
testcase_25 AC 137 ms
78,980 KB
testcase_26 AC 138 ms
79,540 KB
testcase_27 AC 133 ms
80,000 KB
testcase_28 AC 136 ms
78,600 KB
testcase_29 AC 136 ms
79,968 KB
testcase_30 AC 137 ms
79,336 KB
testcase_31 AC 143 ms
79,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt, ceil


def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False
    for i in range(2, n + 1):
        if lst[i]:
            S.add(i)
    return sorted(list(S))

K = int(input())
N = int(input())
S = Sieve(N + 5)

from collections import *
Q = deque()
seen = [0] * 10

def f(x):
    while len(str(x)) != 1:
        v = 0
        while x:
            v += x % 10
            x //= 10
        x = v
    return x

ans = -1
maxv = -1
for s in S:
    if s < K or s > N:
        continue
    q = f(s)
    seen[q] += 1
    Q.append(s)
    while seen[q] == 2:
        seen[f(Q.popleft())] -= 1

    if len(Q) >= maxv:
        ans = Q[0]
        maxv = len(Q)

print(ans)
0