結果

問題 No.6 使いものにならないハッシュ
ユーザー H3PO4H3PO4
提出日時 2020-04-17 11:03:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 678 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 10,604 KB
最終ジャッジ日時 2023-10-14 23:23:07
合計ジャッジ時間 3,219 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,848 KB
testcase_01 AC 14 ms
7,816 KB
testcase_02 AC 104 ms
10,604 KB
testcase_03 AC 30 ms
8,664 KB
testcase_04 AC 37 ms
8,944 KB
testcase_05 AC 40 ms
9,132 KB
testcase_06 AC 64 ms
9,664 KB
testcase_07 AC 47 ms
9,536 KB
testcase_08 AC 61 ms
9,716 KB
testcase_09 AC 44 ms
9,612 KB
testcase_10 AC 14 ms
7,764 KB
testcase_11 AC 30 ms
8,744 KB
testcase_12 AC 73 ms
9,896 KB
testcase_13 AC 39 ms
9,520 KB
testcase_14 AC 44 ms
9,592 KB
testcase_15 AC 61 ms
9,412 KB
testcase_16 AC 54 ms
9,884 KB
testcase_17 AC 81 ms
10,400 KB
testcase_18 AC 98 ms
10,292 KB
testcase_19 AC 78 ms
10,156 KB
testcase_20 AC 70 ms
10,032 KB
testcase_21 AC 25 ms
8,404 KB
testcase_22 AC 74 ms
10,184 KB
testcase_23 AC 70 ms
9,988 KB
testcase_24 AC 72 ms
10,008 KB
testcase_25 AC 49 ms
9,524 KB
testcase_26 AC 85 ms
10,304 KB
testcase_27 AC 68 ms
9,980 KB
testcase_28 AC 49 ms
9,412 KB
testcase_29 AC 90 ms
10,220 KB
testcase_30 AC 80 ms
10,076 KB
testcase_31 AC 72 ms
10,136 KB
権限があれば一括ダウンロードができます

ソースコード

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