結果

問題 No.6 使いものにならないハッシュ
ユーザー lloyzlloyz
提出日時 2022-03-09 22:56:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 972 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 79,944 KB
最終ジャッジ日時 2023-10-12 00:30:32
合計ジャッジ時間 6,035 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
78,852 KB
testcase_01 AC 108 ms
79,004 KB
testcase_02 AC 127 ms
79,944 KB
testcase_03 AC 123 ms
79,360 KB
testcase_04 AC 124 ms
79,632 KB
testcase_05 AC 125 ms
79,376 KB
testcase_06 AC 127 ms
79,432 KB
testcase_07 AC 121 ms
79,292 KB
testcase_08 AC 121 ms
79,124 KB
testcase_09 AC 122 ms
79,332 KB
testcase_10 AC 107 ms
78,796 KB
testcase_11 AC 124 ms
79,388 KB
testcase_12 AC 129 ms
79,576 KB
testcase_13 AC 118 ms
79,456 KB
testcase_14 AC 122 ms
79,424 KB
testcase_15 AC 123 ms
79,384 KB
testcase_16 AC 125 ms
79,512 KB
testcase_17 AC 123 ms
79,420 KB
testcase_18 AC 127 ms
79,696 KB
testcase_19 AC 127 ms
79,348 KB
testcase_20 AC 127 ms
79,528 KB
testcase_21 AC 121 ms
79,520 KB
testcase_22 AC 124 ms
79,244 KB
testcase_23 AC 124 ms
79,448 KB
testcase_24 AC 125 ms
79,324 KB
testcase_25 AC 125 ms
79,720 KB
testcase_26 AC 124 ms
79,384 KB
testcase_27 AC 124 ms
79,508 KB
testcase_28 AC 123 ms
79,332 KB
testcase_29 AC 125 ms
79,236 KB
testcase_30 AC 127 ms
79,560 KB
testcase_31 AC 121 ms
79,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

IsPrime = [True for _ in range(2 * 10**5 + 1)]
IsPrime[0] = IsPrime[1] = False
for i in range(2, 2 * 10**5 + 1):
    if IsPrime[i]:
        for j in range(i + i, 2 * 10**5 + 1, i):
            IsPrime[j] = False

n = int(input())
k = int(input())

from collections import defaultdict

Prime = []
L = []
for i in range(n, k + 1):
    if IsPrime[i]:
        Prime.append(i)
        ic = i
        while ic > 9:
            temp = 0
            while ic != 0:
                temp += ic % 10
                ic //= 10
            ic = temp
        L.append(ic)

m = len(Prime)
counter = defaultdict(int)
DP = [0 for _ in range(m)]
right = 0
length = 0
ans = 0
for left in range(m):
    while right < m:
        counter[L[right]] += 1
        if counter[L[right]] == 2:
            counter[L[right]] -= 1
            break
        right += 1
    if right - left >= length:
        length = right - left
        ans = max(ans, Prime[left])
    counter[L[left]] -= 1
print(ans)
0