結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-08-06 00:20:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 307 ms / 1,000 ms
コード長 940 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 88,824 KB
最終ジャッジ日時 2024-05-09 10:35:42
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,352 KB
testcase_01 AC 44 ms
52,352 KB
testcase_02 AC 43 ms
51,968 KB
testcase_03 AC 76 ms
72,320 KB
testcase_04 AC 44 ms
52,480 KB
testcase_05 AC 48 ms
52,480 KB
testcase_06 AC 48 ms
51,968 KB
testcase_07 AC 48 ms
52,096 KB
testcase_08 AC 48 ms
51,968 KB
testcase_09 AC 44 ms
52,352 KB
testcase_10 AC 44 ms
52,096 KB
testcase_11 AC 46 ms
52,224 KB
testcase_12 AC 44 ms
52,608 KB
testcase_13 AC 43 ms
52,480 KB
testcase_14 AC 51 ms
59,392 KB
testcase_15 AC 43 ms
51,840 KB
testcase_16 AC 43 ms
52,480 KB
testcase_17 AC 44 ms
52,224 KB
testcase_18 AC 43 ms
52,224 KB
testcase_19 AC 91 ms
76,828 KB
testcase_20 AC 134 ms
79,784 KB
testcase_21 AC 43 ms
51,840 KB
testcase_22 AC 43 ms
52,096 KB
testcase_23 AC 43 ms
52,096 KB
testcase_24 AC 42 ms
52,224 KB
testcase_25 AC 182 ms
82,412 KB
testcase_26 AC 43 ms
52,224 KB
testcase_27 AC 43 ms
51,968 KB
testcase_28 AC 43 ms
52,224 KB
testcase_29 AC 43 ms
52,864 KB
testcase_30 AC 43 ms
51,968 KB
testcase_31 AC 44 ms
52,480 KB
testcase_32 AC 122 ms
79,292 KB
testcase_33 AC 307 ms
88,824 KB
testcase_34 AC 301 ms
88,700 KB
testcase_35 AC 170 ms
82,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

# すみません
# 念のため再提出
# arrayと内包表記のため速くなっている?

import array

MIN_N = 3
MAX_N = 10 ** 6
MIN_L = 1
MAX_L = 10 ** 7


def sieve_of_eratosthenes(end, typecode="L"):
    assert end > 1
    is_prime = array.array("B", (True for i in range(end)))
    is_prime[0] = False
    is_prime[1] = False
    primes = array.array(typecode)
    for i in range(2, end):
        if is_prime[i]:
            primes.append(i)
            for j in range(2 * i, end, i):
                is_prime[j] = False
    return primes


def count_sequences(n, l):
    d_max = l // (n - 1)
    if d_max < 2:
        return 0
    ds = sieve_of_eratosthenes(d_max + 1)
    return sum(l - (n - 1) * d + 1 for d in ds)


def main():
    n, l = map(int, input().split())
    assert MIN_N <= n <= MAX_N
    assert MIN_L <= l <= MAX_L
    print(count_sequences(n, l))


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