結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー しらっ亭
提出日時 2016-08-06 00:57:59
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 304 ms / 1,000 ms
コード長 826 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 49,016 KB
最終ジャッジ日時 2024-12-15 22:52:53
合計ジャッジ時間 3,268 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

# パクった
def primes2(limit):
    ''' returns a list of prime numbers upto limit.
    source: Rossetta code: Sieve of Eratosthenes
    http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Odds-only_version_of_the_array_sieve_above
    '''
    if limit < 2: return []
    if limit < 3: return [2]
    lmtbf = (limit - 3) // 2
    buf = [True] * (lmtbf + 1)
    for i in range((int(limit ** 0.5) - 3) // 2 + 1):
        if buf[i]:
            p = i + i + 3
            s = p * (i + 1) + i
            buf[s::p] = [False] * ((lmtbf - s) // p + 1)
    return [2] + [i + i + 3 for i, v in enumerate(buf) if v]


def solve():
    N, L = map(int, input().split())

    ps = primes2(L // (N - 1))

    ans = 0
    for p in ps:
        a = L - p * (N - 1)
        ans += a + 1
    print(ans)


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