結果

問題 No.6 使いものにならないハッシュ
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-04-21 17:24:04
言語 Python2
(2.7.18)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 1,155 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 6,728 KB
実行使用メモリ 9,844 KB
最終ジャッジ日時 2023-10-14 22:51:08
合計ジャッジ時間 2,541 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,792 KB
testcase_01 AC 13 ms
6,872 KB
testcase_02 AC 61 ms
9,816 KB
testcase_03 AC 20 ms
7,144 KB
testcase_04 AC 22 ms
7,484 KB
testcase_05 AC 27 ms
7,692 KB
testcase_06 AC 37 ms
8,280 KB
testcase_07 AC 25 ms
7,616 KB
testcase_08 AC 35 ms
7,992 KB
testcase_09 AC 19 ms
7,176 KB
testcase_10 AC 13 ms
6,884 KB
testcase_11 AC 22 ms
7,484 KB
testcase_12 AC 45 ms
8,748 KB
testcase_13 AC 17 ms
7,108 KB
testcase_14 AC 19 ms
7,108 KB
testcase_15 AC 38 ms
8,464 KB
testcase_16 AC 27 ms
7,588 KB
testcase_17 AC 45 ms
8,736 KB
testcase_18 AC 59 ms
9,844 KB
testcase_19 AC 44 ms
8,808 KB
testcase_20 AC 41 ms
8,728 KB
testcase_21 AC 18 ms
7,164 KB
testcase_22 AC 43 ms
8,668 KB
testcase_23 AC 43 ms
8,796 KB
testcase_24 AC 43 ms
8,644 KB
testcase_25 AC 29 ms
7,576 KB
testcase_26 AC 49 ms
8,988 KB
testcase_27 AC 38 ms
8,544 KB
testcase_28 AC 30 ms
7,876 KB
testcase_29 AC 53 ms
9,244 KB
testcase_30 AC 49 ms
9,072 KB
testcase_31 AC 43 ms
8,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
def segment_sieve(a, b):
    sqb = int(b ** .5)
    is_prime_small = [0, 0] + [1] * (sqb - 1)
    is_prime = [a!=1] + [1] * (b - a - 1)
    i = 2
    while i * i < b:
        if is_prime_small[i]:
            j = 2 * i
            while j * j < b:
                is_prime_small[j] = 0
                j += i
            for j in xrange(max(2, (a+i-1)/i) * i, b, i):
                is_prime[j - a] = 0
        i += 1
    return [i+a for i, p in enumerate(is_prime) if p]

digit_sum = lambda x: 9 if x%9==0 and x!=0 else x%9

from collections import namedtuple
Range = namedtuple('Range', 'left, right')

k = int(raw_input())
n = int(raw_input())
primes = segment_sieve(k, n+1)
hashes = map(digit_sum, primes)
left, right, hashes_size = 0, 0, len(hashes)
checked = [0] * 10
res = None
hamark = 0
while left < hashes_size:
    while right < hashes_size:
        x = hashes[right]
        if checked[x]:
            break
        right += 1
        checked[x] = 1
    dif = right - left
    if dif >= hamark:
        hamark = dif
        res = Range(left, right)
    x = hashes[left]
    checked[x] = 0
    left += 1
print primes[res.left]
0