結果

問題 No.6 使いものにならないハッシュ
コンテスト
ユーザー gigurururu
提出日時 2014-11-04 16:44:05
言語 PyPy2
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 780 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 136 ms
コンパイル使用メモリ 77,304 KB
最終ジャッジ日時 2025-12-03 12:54:20
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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