結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー rpy3cpprpy3cpp
提出日時 2016-08-05 22:37:01
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 250 ms / 1,000 ms
コード長 1,151 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 46,620 KB
最終ジャッジ日時 2023-08-22 02:34:20
合計ジャッジ時間 3,013 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,840 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 AC 16 ms
7,812 KB
testcase_03 AC 22 ms
9,432 KB
testcase_04 AC 15 ms
7,812 KB
testcase_05 AC 15 ms
7,832 KB
testcase_06 AC 16 ms
7,836 KB
testcase_07 AC 15 ms
7,896 KB
testcase_08 AC 15 ms
7,780 KB
testcase_09 AC 16 ms
7,840 KB
testcase_10 AC 16 ms
7,812 KB
testcase_11 AC 15 ms
7,880 KB
testcase_12 AC 15 ms
7,832 KB
testcase_13 AC 15 ms
7,804 KB
testcase_14 AC 15 ms
7,856 KB
testcase_15 AC 15 ms
7,844 KB
testcase_16 AC 15 ms
7,804 KB
testcase_17 AC 15 ms
7,820 KB
testcase_18 AC 15 ms
7,816 KB
testcase_19 AC 40 ms
12,240 KB
testcase_20 AC 84 ms
20,100 KB
testcase_21 AC 15 ms
7,812 KB
testcase_22 AC 15 ms
7,812 KB
testcase_23 AC 15 ms
7,820 KB
testcase_24 AC 15 ms
7,804 KB
testcase_25 AC 129 ms
27,692 KB
testcase_26 AC 16 ms
7,796 KB
testcase_27 AC 16 ms
7,836 KB
testcase_28 AC 15 ms
7,836 KB
testcase_29 AC 16 ms
7,748 KB
testcase_30 AC 15 ms
7,840 KB
testcase_31 AC 15 ms
7,836 KB
testcase_32 AC 72 ms
17,928 KB
testcase_33 AC 248 ms
46,520 KB
testcase_34 AC 250 ms
46,620 KB
testcase_35 AC 121 ms
25,992 KB
権限があれば一括ダウンロードができます

ソースコード

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]

N, L = map(int, input().split())

def solve(N, L):
    '''
    素数 d を一つ選ぶと、
    0 <= x0 かつ   x(N-1) = d * (N - 1) + x0 <= L を満たす。
    すなわち、
    0 <= x0 <= L - d * (N - 1)
    x0 は、L - d * (N - 1) + 1 通りの値をとりうる。
    L - d * (N - 1) >= 0
    2 <= d <= L//(N - 1)
    の範囲の素数について、上記の和を取ればよい。で、
    '''
    dmax = L // (N - 1)
    ps = primes2(dmax)
    ans = 0
    for p in ps:
        ans += L - p * (N - 1) + 1
    return ans

print(solve(N, L))
0