結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,420 KB
testcase_01 AC 16 ms
8,416 KB
testcase_02 AC 61 ms
10,924 KB
testcase_03 AC 24 ms
8,708 KB
testcase_04 AC 30 ms
9,348 KB
testcase_05 AC 29 ms
9,032 KB
testcase_06 AC 43 ms
9,760 KB
testcase_07 AC 37 ms
9,772 KB
testcase_08 AC 41 ms
10,020 KB
testcase_09 AC 42 ms
10,912 KB
testcase_10 AC 16 ms
8,536 KB
testcase_11 AC 25 ms
8,688 KB
testcase_12 AC 46 ms
9,788 KB
testcase_13 AC 39 ms
10,692 KB
testcase_14 AC 40 ms
10,532 KB
testcase_15 AC 41 ms
9,820 KB
testcase_16 AC 42 ms
10,456 KB
testcase_17 AC 52 ms
10,904 KB
testcase_18 AC 58 ms
10,908 KB
testcase_19 AC 53 ms
10,616 KB
testcase_20 AC 46 ms
10,084 KB
testcase_21 AC 21 ms
8,632 KB
testcase_22 AC 49 ms
10,352 KB
testcase_23 AC 47 ms
9,792 KB
testcase_24 AC 47 ms
10,080 KB
testcase_25 AC 38 ms
9,744 KB
testcase_26 AC 54 ms
10,628 KB
testcase_27 AC 47 ms
10,392 KB
testcase_28 AC 35 ms
9,556 KB
testcase_29 AC 54 ms
10,548 KB
testcase_30 AC 50 ms
10,056 KB
testcase_31 AC 49 ms
10,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


def sieve(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]:
            mark(s, 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