結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-07-10 17:21:39
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 316 ms / 1,000 ms
コード長 1,006 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 89,864 KB
最終ジャッジ日時 2023-08-21 22:09:45
合計ジャッジ時間 5,913 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,612 KB
testcase_01 AC 81 ms
71,296 KB
testcase_02 AC 80 ms
71,272 KB
testcase_03 AC 131 ms
77,792 KB
testcase_04 AC 78 ms
71,152 KB
testcase_05 AC 76 ms
71,732 KB
testcase_06 AC 75 ms
71,568 KB
testcase_07 AC 75 ms
71,372 KB
testcase_08 AC 75 ms
71,176 KB
testcase_09 AC 77 ms
71,364 KB
testcase_10 AC 77 ms
71,568 KB
testcase_11 AC 76 ms
71,008 KB
testcase_12 AC 77 ms
71,224 KB
testcase_13 AC 75 ms
71,564 KB
testcase_14 AC 81 ms
76,156 KB
testcase_15 AC 76 ms
71,428 KB
testcase_16 AC 77 ms
71,380 KB
testcase_17 AC 78 ms
71,520 KB
testcase_18 AC 76 ms
71,652 KB
testcase_19 AC 109 ms
78,604 KB
testcase_20 AC 152 ms
80,964 KB
testcase_21 AC 76 ms
71,324 KB
testcase_22 AC 77 ms
71,176 KB
testcase_23 AC 76 ms
71,508 KB
testcase_24 AC 77 ms
71,416 KB
testcase_25 AC 200 ms
83,348 KB
testcase_26 AC 78 ms
71,360 KB
testcase_27 AC 77 ms
71,184 KB
testcase_28 AC 76 ms
71,528 KB
testcase_29 AC 77 ms
71,576 KB
testcase_30 AC 76 ms
71,456 KB
testcase_31 AC 77 ms
71,592 KB
testcase_32 AC 144 ms
80,108 KB
testcase_33 AC 310 ms
89,740 KB
testcase_34 AC 316 ms
89,864 KB
testcase_35 AC 194 ms
83,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

# 制約再変更後の想定解
# 以前のWriter解はリジャッジでREまたはTLEとなるはず

import array

MIN_N = 3
MAX_N = 10 ** 6
MIN_L = 1
MAX_L = 2 * 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):
    def x_max(d):
        return l - (n - 1) * d
    d_max = l // (n - 1)
    if d_max < 2:
        return 0
    ds = sieve_of_eratosthenes(d_max + 1)
    ans = sum(x_max(d) + 1 for d in ds)
    return ans


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