結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー nanaenanae
提出日時 2017-02-23 06:08:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 227 ms / 1,000 ms
コード長 1,540 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 11,068 KB
実行使用メモリ 19,544 KB
最終ジャッジ日時 2023-08-30 03:30:04
合計ジャッジ時間 2,803 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,484 KB
testcase_01 AC 17 ms
8,396 KB
testcase_02 AC 17 ms
8,460 KB
testcase_03 AC 23 ms
8,952 KB
testcase_04 AC 17 ms
8,340 KB
testcase_05 AC 17 ms
8,784 KB
testcase_06 AC 17 ms
8,716 KB
testcase_07 AC 16 ms
8,724 KB
testcase_08 AC 17 ms
8,396 KB
testcase_09 AC 17 ms
8,788 KB
testcase_10 AC 17 ms
8,420 KB
testcase_11 AC 17 ms
8,392 KB
testcase_12 AC 17 ms
8,344 KB
testcase_13 AC 17 ms
8,488 KB
testcase_14 AC 17 ms
8,584 KB
testcase_15 AC 17 ms
8,344 KB
testcase_16 AC 17 ms
8,640 KB
testcase_17 AC 17 ms
8,480 KB
testcase_18 AC 17 ms
8,592 KB
testcase_19 AC 40 ms
9,708 KB
testcase_20 AC 80 ms
11,876 KB
testcase_21 AC 17 ms
8,340 KB
testcase_22 AC 17 ms
8,416 KB
testcase_23 AC 17 ms
8,700 KB
testcase_24 AC 17 ms
8,484 KB
testcase_25 AC 119 ms
14,124 KB
testcase_26 AC 17 ms
8,532 KB
testcase_27 AC 17 ms
8,428 KB
testcase_28 AC 16 ms
8,424 KB
testcase_29 AC 17 ms
8,644 KB
testcase_30 AC 17 ms
8,480 KB
testcase_31 AC 17 ms
8,668 KB
testcase_32 AC 70 ms
11,228 KB
testcase_33 AC 227 ms
19,544 KB
testcase_34 AC 224 ms
19,404 KB
testcase_35 AC 111 ms
13,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import sqrt

def solve():
    N, L = map(int, input().split())
    limit = L // (N - 1) + 1

    ans = 0

    for p in primes235(limit):
        if L - (N - 1) * p + 1 <= 0:
            break
        ans += L - (N - 1) * p + 1

    print(ans)

def primes235(limit):
    # http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Factorization_wheel235_version_of_the_generator_version
    yield 2; yield 3; yield 5
    if limit < 7: 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] # 2 loops for overflow
    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 # integral number of wheels rounded up
    lmtsqrt = (int(limit ** 0.5) - 7)
    lmtsqrt = lmtsqrt // 30 * 8 + ndxs[lmtsqrt % 30] # round down on the wheel
    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])): # adjust for extras
        if buf[i]: yield (30 * (i >> 3) + modPrms[i & 7])

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

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