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