結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー GrayCoderGrayCoder
提出日時 2018-05-27 16:19:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 431 ms / 1,000 ms
コード長 578 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 155,604 KB
最終ジャッジ日時 2023-09-11 04:41:38
合計ジャッジ時間 6,228 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,712 KB
testcase_01 AC 73 ms
71,484 KB
testcase_02 AC 76 ms
71,336 KB
testcase_03 AC 86 ms
78,160 KB
testcase_04 AC 75 ms
71,428 KB
testcase_05 AC 77 ms
71,656 KB
testcase_06 AC 78 ms
71,660 KB
testcase_07 AC 77 ms
71,860 KB
testcase_08 AC 79 ms
71,440 KB
testcase_09 AC 76 ms
71,836 KB
testcase_10 AC 76 ms
71,616 KB
testcase_11 AC 77 ms
71,260 KB
testcase_12 AC 76 ms
71,116 KB
testcase_13 AC 75 ms
71,516 KB
testcase_14 AC 79 ms
75,180 KB
testcase_15 AC 75 ms
71,392 KB
testcase_16 AC 74 ms
71,928 KB
testcase_17 AC 75 ms
71,504 KB
testcase_18 AC 76 ms
71,608 KB
testcase_19 AC 103 ms
84,664 KB
testcase_20 AC 146 ms
100,204 KB
testcase_21 AC 76 ms
71,428 KB
testcase_22 AC 79 ms
71,508 KB
testcase_23 AC 78 ms
71,660 KB
testcase_24 AC 75 ms
71,844 KB
testcase_25 AC 235 ms
116,608 KB
testcase_26 AC 76 ms
71,520 KB
testcase_27 AC 76 ms
71,104 KB
testcase_28 AC 77 ms
71,860 KB
testcase_29 AC 78 ms
71,656 KB
testcase_30 AC 76 ms
70,968 KB
testcase_31 AC 76 ms
71,644 KB
testcase_32 AC 131 ms
86,352 KB
testcase_33 AC 431 ms
155,604 KB
testcase_34 AC 413 ms
115,964 KB
testcase_35 AC 212 ms
94,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    n = L // (N - 1)
    lst = erastosthenes(n)
    cnt = L - (N - 1) * 2 + 1
    for i in range(3, n + 1, 2):
        if lst[i]:
            cnt += L - (N - 1) * i + 1
    print(cnt)

def erastosthenes(n):
    prime = [0, 1] * ((n + 1) // 2)
    if not n % 2:
        prime += [0]
    prime[1], prime[2] = 0, 1

    sqrt = n ** 0.5
    i = 3
    while i <= sqrt:
        for j in range(i ** 2, n + 1, i):
            prime[j] = 0
        i += 2
    return prime

main()
0