結果

問題 No.6 使いものにならないハッシュ
ユーザー gahougahou
提出日時 2016-11-11 17:01:16
言語 Python2
(2.7.18)
結果
AC  
実行時間 350 ms / 5,000 ms
コード長 955 bytes
コンパイル時間 662 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 6,724 KB
最終ジャッジ日時 2023-10-14 23:03:59
合計ジャッジ時間 11,325 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 251 ms
6,396 KB
testcase_01 AC 257 ms
6,416 KB
testcase_02 AC 350 ms
6,716 KB
testcase_03 AC 258 ms
6,472 KB
testcase_04 AC 269 ms
6,472 KB
testcase_05 AC 286 ms
6,508 KB
testcase_06 AC 297 ms
6,688 KB
testcase_07 AC 273 ms
6,456 KB
testcase_08 AC 287 ms
6,548 KB
testcase_09 AC 263 ms
6,400 KB
testcase_10 AC 243 ms
6,396 KB
testcase_11 AC 267 ms
6,612 KB
testcase_12 AC 309 ms
6,636 KB
testcase_13 AC 250 ms
6,476 KB
testcase_14 AC 264 ms
6,476 KB
testcase_15 AC 294 ms
6,576 KB
testcase_16 AC 270 ms
6,592 KB
testcase_17 AC 315 ms
6,704 KB
testcase_18 AC 342 ms
6,576 KB
testcase_19 AC 316 ms
6,596 KB
testcase_20 AC 307 ms
6,632 KB
testcase_21 AC 263 ms
6,508 KB
testcase_22 AC 302 ms
6,632 KB
testcase_23 AC 303 ms
6,568 KB
testcase_24 AC 308 ms
6,592 KB
testcase_25 AC 280 ms
6,476 KB
testcase_26 AC 322 ms
6,596 KB
testcase_27 AC 302 ms
6,540 KB
testcase_28 AC 280 ms
6,552 KB
testcase_29 AC 323 ms
6,572 KB
testcase_30 AC 317 ms
6,724 KB
testcase_31 AC 311 ms
6,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isPrime(n,lst):
  for i in xrange(len(lst)):
    if n%lst[i]==0: return False
    if n<=lst[i]**2: return True

def primes():
  lst=[2]
  n=3
  while True:
    if n > 2*10**5: break
    if isPrime(n,lst):
      lst.append(n)
    n+=2
  return lst

def hashnize(n):
  k=n
  while k>9:
    k=sum(map(int,list(str(k))))
  return k

def hashPrime(lst):
  newLst=[]
  for i in lst:
    newLst.append(hashnize(i))
  return newLst

K=int(raw_input())
N=int(raw_input())
ps=[]
p=primes()
for i in p:
  if K<=i and i<=N:
    ps.append(i)
  if N<i: break
hashP = hashPrime(ps)
dic={}
maxLength=0
maxA=-1
a=0
b=0
while True:
  # print "%d,%d" % (a,b)
  # print dic
  if b==len(hashP):
    if maxLength<=b-a:
      maxA=a
    break
  if hashP[b] in dic:
    if maxLength<=b-a:
      maxA=a
      maxLength=b-a
    while hashP[b] in dic:
      del dic[hashP[a]]
      a+=1
    dic[hashP[b]] = True
    b+=1
  else:
    dic[hashP[b]] = True
    b+=1
print ps[maxA]
0