結果

問題 No.6 使いものにならないハッシュ
ユーザー DialBirdDialBird
提出日時 2019-07-22 21:50:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 886 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 13,820 KB
最終ジャッジ日時 2024-09-16 16:50:04
合計ジャッジ時間 3,717 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,752 KB
testcase_01 AC 33 ms
10,624 KB
testcase_02 AC 96 ms
13,076 KB
testcase_03 AC 45 ms
11,228 KB
testcase_04 AC 60 ms
12,136 KB
testcase_05 AC 50 ms
11,564 KB
testcase_06 AC 79 ms
12,680 KB
testcase_07 AC 87 ms
12,576 KB
testcase_08 AC 85 ms
13,000 KB
testcase_09 AC 119 ms
13,820 KB
testcase_10 AC 31 ms
10,624 KB
testcase_11 AC 42 ms
11,228 KB
testcase_12 AC 74 ms
12,344 KB
testcase_13 AC 113 ms
13,764 KB
testcase_14 AC 113 ms
13,776 KB
testcase_15 AC 70 ms
12,408 KB
testcase_16 AC 103 ms
13,344 KB
testcase_17 AC 101 ms
13,312 KB
testcase_18 AC 93 ms
13,056 KB
testcase_19 AC 99 ms
13,144 KB
testcase_20 AC 85 ms
12,424 KB
testcase_21 AC 38 ms
11,008 KB
testcase_22 AC 98 ms
13,240 KB
testcase_23 AC 76 ms
12,484 KB
testcase_24 AC 87 ms
12,804 KB
testcase_25 AC 83 ms
13,092 KB
testcase_26 AC 94 ms
13,272 KB
testcase_27 AC 97 ms
13,108 KB
testcase_28 AC 64 ms
12,200 KB
testcase_29 AC 93 ms
13,020 KB
testcase_30 AC 83 ms
12,420 KB
testcase_31 AC 87 ms
12,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def primes(n):
    if n < 1:
        return []

    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return [i for i in range(2, n+1) if is_prime[i]]

def main():
    """ main """
    # 1 N
    K = int(input())
    # 2 200000
    N = int(input())
    ps = sorted(set(primes(N)) - set(primes(K-1)))
    # しゃくとり
    shakutori = [ps[0]]
    # 答え
    ans = ps[0]
    # 最大長
    maxlength = 1

    for i in ps[1:]:
        for idx, j in enumerate(shakutori):
            if i%9 == j%9:
                shakutori = shakutori[idx+1:]

        shakutori.append(i)

        if maxlength <= len(shakutori):
            maxlength = len(shakutori)
            ans = shakutori[0]

    print(ans)


main()
0