結果

問題 No.6 使いものにならないハッシュ
ユーザー AAAR SalmonAAAR Salmon
提出日時 2021-05-22 18:13:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 670 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 78,464 KB
最終ジャッジ日時 2024-04-18 23:03:06
合計ジャッジ時間 3,983 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,224 KB
testcase_01 AC 37 ms
52,352 KB
testcase_02 AC 73 ms
77,516 KB
testcase_03 WA -
testcase_04 AC 70 ms
75,840 KB
testcase_05 AC 78 ms
76,928 KB
testcase_06 WA -
testcase_07 AC 79 ms
77,300 KB
testcase_08 AC 93 ms
77,304 KB
testcase_09 WA -
testcase_10 AC 41 ms
52,480 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 98 ms
77,696 KB
testcase_20 AC 93 ms
77,568 KB
testcase_21 AC 68 ms
69,760 KB
testcase_22 WA -
testcase_23 AC 87 ms
77,676 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 101 ms
77,760 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stderr


def hash(n: int):
	res = n
	while res >= 10:
		n = res
		res = 0
		while n > 0:
			res += n % 10
			n //= 10
	return res

K = int(input())
N = int(input())

isprime = [True] * (N + 1)
isprime[0] = isprime[1] = False
for i in range(2, N + 1):
	if isprime[i]:
		for j in range(i * 2, N + 1, i):
			isprime[j] = False

maxlen = len = 0
bkt = [-1] * 10
ans = 0

for i in range(K, N + 1):
	if not isprime[i]:
		continue
	h = hash(i)
	if bkt[h] != -1:
		for j in range(10):
			rem = bkt[h]
			if 0 <= bkt[j] <= rem:
				bkt[j] = -1
				len -= 1
	bkt[h] = i
	len += 1
	if len >= maxlen:
		ans = min(v for v in bkt if v >= 0)
		maxlen = len

print(ans)
0