結果

問題 No.6 使いものにならないハッシュ
ユーザー ytft
提出日時 2022-11-02 14:44:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 570 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 78,592 KB
最終ジャッジ日時 2024-07-17 04:07:05
合計ジャッジ時間 3,968 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,copy
input=lambda:sys.stdin.readline().rstrip()
def has(a):
	if a<10:
		return a
	temp=0
	while a>0:
		temp+=a%10
		a//=10
	return has(temp)
K=int(input())
N=int(input())
isPrime=[1 for i in range(N+1)]
primes=[]
for i in range(2,N+1):
	if isPrime[i]:
		for j in range(i*2,N+1,i):
			isPrime[j]=0
		if K<=i:
			primes.append(i)
P=[has(i) for i in primes]
big,cur,ans=0,1,0
count=[0 for i in range(10)]
for end in range(len(P)):
	count[P[end]]+=1
	while max(count)>1:
		count[P[big]]-=1
		big+=1
	if cur<=end-big+1:
		cur=end-big+1
		ans=big
print(primes[ans])
0