結果

問題 No.6 使いものにならないハッシュ
ユーザー gahougahou
提出日時 2016-11-11 16:56:32
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-05-04 02:09:36
合計ジャッジ時間 10,313 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
6,912 KB
testcase_01 AC 240 ms
6,784 KB
testcase_02 AC 340 ms
7,296 KB
testcase_03 AC 260 ms
6,912 KB
testcase_04 AC 275 ms
7,040 KB
testcase_05 AC 273 ms
6,784 KB
testcase_06 AC 290 ms
7,040 KB
testcase_07 AC 268 ms
7,040 KB
testcase_08 AC 282 ms
6,912 KB
testcase_09 AC 256 ms
6,912 KB
testcase_10 AC 250 ms
6,784 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 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 314 ms
7,040 KB
testcase_31 AC 302 ms
7,040 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+1:
      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