結果

問題 No.6 使いものにならないハッシュ
ユーザー DialBirdDialBird
提出日時 2019-07-22 21:50:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 886 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 11,312 KB
最終ジャッジ日時 2023-10-14 23:17:27
合計ジャッジ時間 2,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,972 KB
testcase_01 AC 15 ms
7,820 KB
testcase_02 AC 70 ms
10,544 KB
testcase_03 AC 24 ms
8,768 KB
testcase_04 AC 38 ms
9,448 KB
testcase_05 AC 30 ms
9,060 KB
testcase_06 AC 55 ms
10,120 KB
testcase_07 AC 58 ms
9,940 KB
testcase_08 AC 59 ms
10,540 KB
testcase_09 AC 88 ms
11,312 KB
testcase_10 AC 14 ms
7,824 KB
testcase_11 AC 24 ms
8,592 KB
testcase_12 AC 48 ms
9,700 KB
testcase_13 AC 85 ms
11,284 KB
testcase_14 AC 83 ms
11,020 KB
testcase_15 AC 47 ms
9,596 KB
testcase_16 AC 75 ms
10,616 KB
testcase_17 AC 73 ms
10,808 KB
testcase_18 AC 65 ms
10,576 KB
testcase_19 AC 69 ms
10,676 KB
testcase_20 AC 58 ms
9,752 KB
testcase_21 AC 20 ms
8,504 KB
testcase_22 AC 66 ms
10,640 KB
testcase_23 AC 52 ms
9,720 KB
testcase_24 AC 61 ms
10,112 KB
testcase_25 AC 57 ms
10,548 KB
testcase_26 AC 67 ms
10,408 KB
testcase_27 AC 68 ms
10,636 KB
testcase_28 AC 42 ms
9,512 KB
testcase_29 AC 65 ms
10,584 KB
testcase_30 AC 56 ms
9,820 KB
testcase_31 AC 61 ms
10,080 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