結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー GrayCoderGrayCoder
提出日時 2020-04-18 10:44:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 227 ms / 1,000 ms
コード長 1,195 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,552 KB
最終ジャッジ日時 2024-04-14 20:32:15
合計ジャッジ時間 3,340 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 36 ms
11,008 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 30 ms
10,880 KB
testcase_12 AC 30 ms
10,880 KB
testcase_13 AC 30 ms
10,880 KB
testcase_14 AC 30 ms
10,752 KB
testcase_15 AC 30 ms
10,880 KB
testcase_16 AC 30 ms
10,880 KB
testcase_17 AC 29 ms
10,752 KB
testcase_18 AC 30 ms
10,880 KB
testcase_19 AC 51 ms
11,904 KB
testcase_20 AC 90 ms
14,080 KB
testcase_21 AC 30 ms
10,752 KB
testcase_22 AC 29 ms
10,880 KB
testcase_23 AC 29 ms
10,880 KB
testcase_24 AC 29 ms
10,880 KB
testcase_25 AC 128 ms
16,252 KB
testcase_26 AC 29 ms
10,752 KB
testcase_27 AC 29 ms
10,880 KB
testcase_28 AC 30 ms
10,880 KB
testcase_29 AC 30 ms
10,752 KB
testcase_30 AC 30 ms
10,752 KB
testcase_31 AC 30 ms
10,880 KB
testcase_32 AC 81 ms
13,568 KB
testcase_33 AC 220 ms
21,488 KB
testcase_34 AC 227 ms
21,552 KB
testcase_35 AC 120 ms
15,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, L = map(int, input().split())

    if (N - 1) * 2 > L:
        print(0)
        return

    n = L // (N - 1)
    lst = primes235(n)
    cnt = 0
    for i in lst:
        cnt += L - (N - 1) * i + 1
    print(cnt)


def primes235(limit):
    for i in (2, 3, 5):
        if limit >= i:
            yield i
        else:
            return
    modPrms = [7,11,13,17,19,23,29,31]
    gaps = [4,2,4,2,4,6,2,6,4,2,4,2,4,6,2,6]
    ndxs = [0,0,0,0,1,1,2,2,2,2,3,3,4,4,4,4,5,5,5,5,5,5,6,6,7,7,7,7,7,7]
    lmtbf = (limit + 23) // 30 * 8 - 1
    lmtsqrt = (int(limit ** 0.5) - 7)
    lmtsqrt = lmtsqrt // 30 * 8 + ndxs[lmtsqrt % 30]
    buf = [True] * (lmtbf + 1)
    for i in range(lmtsqrt + 1):
        if buf[i]:
            ci = i & 7; p = 30 * (i >> 3) + modPrms[ci]
            s = p * p - 7; p8 = p << 3
            for j in range(8):
                c = s // 30 * 8 + ndxs[s % 30]
                buf[c::p8] = [False] * ((lmtbf - c) // p8 + 1)
                s += p * gaps[ci]; ci += 1
    for i in range(lmtbf - 6 + (ndxs[(limit - 7) % 30])):
        if buf[i]: yield (30 * (i >> 3) + modPrms[i & 7])


main()
0