結果

問題 No.6 使いものにならないハッシュ
ユーザー gigurururugigurururu
提出日時 2014-11-04 20:24:54
言語 Python2
(2.7.18)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 751 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 6,596 KB
実行使用メモリ 11,072 KB
最終ジャッジ日時 2023-10-14 22:46:41
合計ジャッジ時間 3,647 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,612 KB
testcase_01 AC 14 ms
6,508 KB
testcase_02 AC 134 ms
11,072 KB
testcase_03 AC 32 ms
7,300 KB
testcase_04 AC 42 ms
7,792 KB
testcase_05 AC 50 ms
7,672 KB
testcase_06 AC 77 ms
9,504 KB
testcase_07 AC 53 ms
9,232 KB
testcase_08 AC 70 ms
9,420 KB
testcase_09 AC 46 ms
10,728 KB
testcase_10 RE -
testcase_11 AC 37 ms
7,280 KB
testcase_12 AC 93 ms
9,332 KB
testcase_13 AC 39 ms
10,416 KB
testcase_14 AC 45 ms
10,420 KB
testcase_15 AC 77 ms
8,896 KB
testcase_16 AC 61 ms
10,280 KB
testcase_17 AC 100 ms
10,740 KB
testcase_18 AC 128 ms
10,764 KB
testcase_19 AC 98 ms
10,524 KB
testcase_20 AC 90 ms
9,700 KB
testcase_21 AC 26 ms
7,192 KB
testcase_22 AC 94 ms
10,212 KB
testcase_23 AC 90 ms
9,584 KB
testcase_24 AC 89 ms
10,004 KB
testcase_25 AC 59 ms
9,172 KB
testcase_26 AC 107 ms
10,644 KB
testcase_27 AC 82 ms
10,152 KB
testcase_28 AC 60 ms
8,360 KB
testcase_29 AC 115 ms
10,496 KB
testcase_30 AC 105 ms
10,028 KB
testcase_31 AC 93 ms
9,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
from collections import deque

def h(n):
    while n>9:
        n=sum(map(int,str(n)))
    return n

def prime(max):
    max2 = (max-3)/2
    sieve = [True]*(max2+1)
    for i in range(int((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=sum(cnt)
    if max<=size:
        max=size
        ans=a[0][0]
print ans
0