結果

問題 No.6 使いものにならないハッシュ
ユーザー TawaraTawara
提出日時 2016-07-26 23:38:38
言語 Python2
(2.7.18)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 734 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 6,572 KB
実行使用メモリ 8,468 KB
最終ジャッジ日時 2023-10-14 23:00:25
合計ジャッジ時間 2,858 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,272 KB
testcase_01 AC 12 ms
6,280 KB
testcase_02 AC 70 ms
8,468 KB
testcase_03 AC 21 ms
6,568 KB
testcase_04 AC 27 ms
6,692 KB
testcase_05 AC 29 ms
6,824 KB
testcase_06 AC 44 ms
7,744 KB
testcase_07 AC 34 ms
7,212 KB
testcase_08 AC 44 ms
7,616 KB
testcase_09 AC 35 ms
7,828 KB
testcase_10 AC 12 ms
6,300 KB
testcase_11 AC 22 ms
6,432 KB
testcase_12 AC 51 ms
7,760 KB
testcase_13 AC 32 ms
7,568 KB
testcase_14 AC 34 ms
7,708 KB
testcase_15 AC 44 ms
7,600 KB
testcase_16 AC 40 ms
7,628 KB
testcase_17 AC 56 ms
8,192 KB
testcase_18 AC 67 ms
8,140 KB
testcase_19 AC 55 ms
8,136 KB
testcase_20 AC 50 ms
7,864 KB
testcase_21 AC 18 ms
6,512 KB
testcase_22 AC 52 ms
7,988 KB
testcase_23 AC 49 ms
7,612 KB
testcase_24 AC 51 ms
7,920 KB
testcase_25 AC 37 ms
7,404 KB
testcase_26 AC 59 ms
8,064 KB
testcase_27 AC 49 ms
7,972 KB
testcase_28 AC 35 ms
7,096 KB
testcase_29 AC 62 ms
8,064 KB
testcase_30 AC 56 ms
7,876 KB
testcase_31 AC 52 ms
7,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import defaultdict as ddict
def sieve (n):
	check = [1]*(n+1)
	check[0] = check[1] = 0
	for d in xrange(2,int(math.sqrt(n))+1):
		if check[d] == 0: continue
		for comp in xrange(d*2,n+1,d):
			check[comp] = 0
	return check
def convert(n):
	while n > 9:
		tmp = 0
 		while n > 0:
 			tmp += n%10
 			n /= 10
 		n = tmp
 	return n
K = int(raw_input())
N = int(raw_input())
prime = sieve(N)
l = [i for i in xrange(K,N+1) if prime[i]]
ulhash = ddict(int)
ans = l[0]
maxlen = 1
ulhash[convert(l[0])] = lpos = 0
for rpos in xrange(1,len(l)):
	r = convert(l[rpos])
	if ulhash[r] >= lpos:
		lpos = ulhash[r] + 1
	ulhash[r] = rpos
	if maxlen <= rpos - lpos + 1:
		ans = l[lpos]
		maxlen = rpos - lpos + 1
print ans
0