結果
| 問題 | 
                            No.6 使いものにならないハッシュ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-11-11 16:51:55 | 
| 言語 | Python2  (2.7.18)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 955 bytes | 
| コンパイル時間 | 45 ms | 
| コンパイル使用メモリ | 6,912 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-11-25 08:12:12 | 
| 合計ジャッジ時間 | 1,297 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 3 WA * 3 RE * 26 | 
ソースコード
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 > 10**3: 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]