結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-11 17:01:16 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 356 ms / 5,000 ms |
| コード長 | 955 bytes |
| コンパイル時間 | 85 ms |
| コンパイル使用メモリ | 6,784 KB |
| 実行使用メモリ | 7,168 KB |
| 最終ジャッジ日時 | 2024-09-16 16:37:53 |
| 合計ジャッジ時間 | 10,807 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
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]