結果

問題 No.6 使いものにならないハッシュ
ユーザー gigurururugigurururu
提出日時 2014-11-04 16:44:05
言語 Python2
(2.7.18)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 780 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 6,668 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2023-10-14 22:46:33
合計ジャッジ時間 4,289 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,572 KB
testcase_01 AC 15 ms
6,668 KB
testcase_02 AC 163 ms
11,040 KB
testcase_03 AC 38 ms
7,204 KB
testcase_04 AC 47 ms
7,796 KB
testcase_05 AC 60 ms
7,728 KB
testcase_06 AC 92 ms
9,476 KB
testcase_07 AC 61 ms
9,172 KB
testcase_08 AC 82 ms
9,428 KB
testcase_09 AC 50 ms
10,760 KB
testcase_10 RE -
testcase_11 AC 43 ms
7,440 KB
testcase_12 AC 113 ms
9,440 KB
testcase_13 AC 42 ms
10,524 KB
testcase_14 AC 50 ms
10,508 KB
testcase_15 AC 92 ms
8,984 KB
testcase_16 AC 69 ms
10,316 KB
testcase_17 AC 117 ms
10,860 KB
testcase_18 AC 153 ms
10,740 KB
testcase_19 AC 114 ms
10,532 KB
testcase_20 AC 104 ms
9,676 KB
testcase_21 AC 29 ms
7,232 KB
testcase_22 AC 110 ms
10,300 KB
testcase_23 AC 107 ms
9,540 KB
testcase_24 AC 108 ms
9,972 KB
testcase_25 AC 67 ms
9,244 KB
testcase_26 AC 128 ms
10,660 KB
testcase_27 AC 97 ms
10,144 KB
testcase_28 AC 71 ms
8,420 KB
testcase_29 AC 135 ms
10,568 KB
testcase_30 AC 125 ms
9,912 KB
testcase_31 AC 110 ms
9,892 KB
権限があれば一括ダウンロードができます

ソースコード

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