結果

問題 No.6 使いものにならないハッシュ
ユーザー gigurururu
提出日時 2014-11-04 16:44:05
言語 Python2
(2.7.18)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 780 bytes
コンパイル時間 543 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 11,428 KB
最終ジャッジ日時 2024-09-16 16:21:48
合計ジャッジ時間 3,911 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import deque

def h(n):
    while n>9:
        n=reduce(lambda x,y:x+int(y),str(n),0)
    return n

def prime(max):
    max2 = (max-3)/2
    sieve = [True]*(max2+1)
    for i in range(int((math.sqrt(max)-3)/2)+1):
        if not sieve[i]: continue
        k = i+i+3
        j = k*(i+1)+i
        while j <= max2:
            sieve[j] = False
            j += k
    sieve = [2]+[i+i+3 for i in range(max2+1) if sieve[i]]
    return sieve

k=input()
n=input()
a=deque()
cnt=[0]*10
max=0
ans=0
for i,j in [(i,h(i)) for i in prime(n) if i>=k]:
    a.append((i,j))
    cnt[j]+=1
    while cnt[j]>1:cnt[a.popleft()[1]]-=1
    size=reduce(lambda x,y:x+y,cnt)
    if max<=size:
        max=size
        ans=a[0][0]
print ans
0