結果

問題 No.6 使いものにならないハッシュ
ユーザー nsd_fbnsd_fb
提出日時 2015-02-19 04:08:22
言語 Python2
(2.7.18)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 744 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 6,696 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-10-14 22:49:35
合計ジャッジ時間 3,745 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,956 KB
testcase_01 AC 11 ms
6,096 KB
testcase_02 AC 130 ms
8,088 KB
testcase_03 AC 31 ms
6,208 KB
testcase_04 AC 41 ms
6,576 KB
testcase_05 AC 47 ms
6,480 KB
testcase_06 AC 76 ms
7,400 KB
testcase_07 AC 55 ms
6,996 KB
testcase_08 AC 70 ms
7,072 KB
testcase_09 AC 52 ms
7,400 KB
testcase_10 AC 12 ms
6,024 KB
testcase_11 AC 33 ms
6,328 KB
testcase_12 AC 92 ms
7,340 KB
testcase_13 AC 43 ms
7,300 KB
testcase_14 AC 51 ms
7,332 KB
testcase_15 AC 75 ms
7,080 KB
testcase_16 AC 65 ms
7,384 KB
testcase_17 AC 102 ms
7,868 KB
testcase_18 AC 127 ms
7,928 KB
testcase_19 AC 101 ms
7,600 KB
testcase_20 AC 89 ms
7,368 KB
testcase_21 AC 24 ms
6,036 KB
testcase_22 AC 95 ms
7,664 KB
testcase_23 AC 87 ms
7,368 KB
testcase_24 AC 91 ms
7,392 KB
testcase_25 AC 59 ms
7,136 KB
testcase_26 AC 108 ms
7,860 KB
testcase_27 AC 85 ms
7,648 KB
testcase_28 AC 60 ms
6,840 KB
testcase_29 AC 112 ms
7,928 KB
testcase_30 AC 102 ms
7,528 KB
testcase_31 AC 93 ms
7,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(k, n):
    res = []
    is_prime = [True] * (n + 1)
    
    for i in xrange(2, n + 1):
        if is_prime[i]:
            if i >= k:
                res.append(i)

            for j in xrange(i * i, n + 1, i):
                is_prime[j] = False

    return res

def frank_hash(n):
    if n < 10:
        return n

    return frank_hash(sum(map(int, str(n))))

k = input()
n = input()

primes = sieve(k, n)
hashes = map(frank_hash, primes)

exists = [False] * 10

max_length = -1
ans = -1

l = 0
for r in xrange(len(primes)):
    while exists[hashes[r]]:
        exists[hashes[l]] = False
        l += 1

    exists[hashes[r]] = True
    if max_length <= r - l + 1:
        max_length = r - l + 1
        ans = primes[l]

print ans
0