結果

問題 No.6 使いものにならないハッシュ
ユーザー しらっ亭しらっ亭
提出日時 2015-08-30 18:39:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 59 ms / 5,000 ms
コード長 977 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 10,872 KB
最終ジャッジ日時 2023-10-14 22:55:10
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,412 KB
testcase_01 AC 15 ms
8,448 KB
testcase_02 AC 59 ms
10,828 KB
testcase_03 AC 23 ms
8,620 KB
testcase_04 AC 26 ms
9,232 KB
testcase_05 AC 26 ms
9,036 KB
testcase_06 AC 38 ms
9,748 KB
testcase_07 AC 32 ms
9,804 KB
testcase_08 AC 36 ms
10,036 KB
testcase_09 AC 40 ms
10,872 KB
testcase_10 AC 14 ms
8,420 KB
testcase_11 AC 23 ms
8,820 KB
testcase_12 AC 46 ms
9,900 KB
testcase_13 AC 37 ms
10,600 KB
testcase_14 AC 38 ms
10,540 KB
testcase_15 AC 39 ms
9,808 KB
testcase_16 AC 41 ms
10,344 KB
testcase_17 AC 49 ms
10,832 KB
testcase_18 AC 56 ms
10,740 KB
testcase_19 AC 52 ms
10,596 KB
testcase_20 AC 43 ms
10,136 KB
testcase_21 AC 18 ms
8,468 KB
testcase_22 AC 46 ms
10,332 KB
testcase_23 AC 42 ms
9,800 KB
testcase_24 AC 45 ms
9,968 KB
testcase_25 AC 35 ms
9,848 KB
testcase_26 AC 49 ms
10,564 KB
testcase_27 AC 45 ms
10,472 KB
testcase_28 AC 33 ms
9,552 KB
testcase_29 AC 51 ms
10,608 KB
testcase_30 AC 47 ms
10,036 KB
testcase_31 AC 46 ms
10,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(n):
    s = [True] * n

    def mark(x):
        for i in range(x + x, n, x):
            s[i] = False

    for x in range(2, int(n ** 0.5) + 1):
        if s[x]:
            mark(x)
    return [i for i in range(n) if s[i] and i > 1]


def dr(n):
    if n == 0:
        return 0
    if n % 9 == 0:
        return 9
    else:
        return n % 9


def solve():
    K = int(input())
    N = int(input())

    hc = [0] * 10
    tc = 0

    ps = [p for p in sieve(N + 1) if p >= K]

    i = j = 0
    ma = 0
    mi = 0

    while i < len(ps):
        if tc == 0 and j < len(ps):
            h = dr(ps[j])
            hc[h] += 1
            if hc[h] >= 2:
                tc += 1
            j += 1
        else:
            h = dr(ps[i])
            hc[h] -= 1
            if hc[h] == 1:
                tc -= 1
            i += 1

        if tc == 0 and j - i >= ma:
            ma = j - i
            mi = i

    print(ps[mi])


if __name__ == '__main__':
    solve()
0