結果

問題 No.6 使いものにならないハッシュ
ユーザー 双六双六
提出日時 2020-07-25 23:58:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 5,000 ms
コード長 1,090 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 80,472 KB
最終ジャッジ日時 2023-10-14 23:25:57
合計ジャッジ時間 6,864 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
80,024 KB
testcase_01 AC 136 ms
79,984 KB
testcase_02 AC 139 ms
79,968 KB
testcase_03 AC 141 ms
80,112 KB
testcase_04 AC 140 ms
80,104 KB
testcase_05 AC 138 ms
79,884 KB
testcase_06 AC 138 ms
80,324 KB
testcase_07 AC 143 ms
80,472 KB
testcase_08 AC 144 ms
80,228 KB
testcase_09 AC 140 ms
80,252 KB
testcase_10 AC 134 ms
80,000 KB
testcase_11 AC 139 ms
80,112 KB
testcase_12 AC 141 ms
79,984 KB
testcase_13 AC 142 ms
80,384 KB
testcase_14 AC 139 ms
80,136 KB
testcase_15 AC 140 ms
80,196 KB
testcase_16 AC 135 ms
80,080 KB
testcase_17 AC 140 ms
80,272 KB
testcase_18 AC 140 ms
80,172 KB
testcase_19 AC 137 ms
80,032 KB
testcase_20 AC 139 ms
80,224 KB
testcase_21 AC 145 ms
80,208 KB
testcase_22 AC 135 ms
80,324 KB
testcase_23 AC 134 ms
80,168 KB
testcase_24 AC 135 ms
80,020 KB
testcase_25 AC 136 ms
80,320 KB
testcase_26 AC 137 ms
80,180 KB
testcase_27 AC 136 ms
80,200 KB
testcase_28 AC 138 ms
80,164 KB
testcase_29 AC 136 ms
80,104 KB
testcase_30 AC 137 ms
80,104 KB
testcase_31 AC 137 ms
80,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

num = 2 * 10 ** 5 + 1 #適当に値を入れる
L = [1 for i in range(num)]; L[0] = 0; L[1] = 0
plist = []
for i in range(num):
	if L[i] == 1:
		plist.append(i); c = 2
		while i * c <= num - 1:
			L[i * c] = 0; c += 1

def hashing(N):
	while N >= 10:
		N = sum(list(map(int, list(str(N)))))

	return N

#処理内容
def main():
	K = int(input())
	N = int(input())
	hashlist = []
	for i in plist:
		x = hashing(i)
		hashlist.append(x)

	M = len(plist)
	# print(hashlist)
	itr = None
	for i in range(M):
		if plist[i] >= K:
			itr = i
			break

	# 尺取り
	D = [0] * 10
	length = 0
	ans = 0
	val = 0
	j = itr
	while itr < M:
		h = hashlist[itr]
		if plist[itr] > N:
			break
		if D[h] == 0:
			D[h] += 1
			val += 1
			itr += 1
		else:
			D[hashlist[j]] -= 1
			val -= 1
			j += 1
		if val >= length:
			length = val
			ans = plist[j]

	print(ans)

if __name__ == '__main__':
	main()
0