結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー htkbhtkb
提出日時 2018-05-27 15:22:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 755 ms / 1,000 ms
コード長 491 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 178,880 KB
最終ジャッジ日時 2023-09-11 04:39:51
合計ジャッジ時間 4,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,004 KB
testcase_01 AC 17 ms
7,956 KB
testcase_02 AC 16 ms
7,976 KB
testcase_03 AC 32 ms
16,800 KB
testcase_04 AC 17 ms
7,900 KB
testcase_05 AC 16 ms
7,904 KB
testcase_06 AC 16 ms
7,936 KB
testcase_07 AC 17 ms
7,924 KB
testcase_08 AC 16 ms
8,000 KB
testcase_09 AC 17 ms
7,948 KB
testcase_10 AC 16 ms
7,992 KB
testcase_11 AC 17 ms
8,012 KB
testcase_12 AC 18 ms
8,104 KB
testcase_13 AC 16 ms
8,008 KB
testcase_14 AC 16 ms
8,108 KB
testcase_15 AC 16 ms
8,108 KB
testcase_16 AC 16 ms
8,012 KB
testcase_17 AC 16 ms
8,112 KB
testcase_18 AC 17 ms
7,988 KB
testcase_19 AC 81 ms
29,420 KB
testcase_20 AC 222 ms
50,780 KB
testcase_21 AC 16 ms
7,908 KB
testcase_22 AC 17 ms
7,948 KB
testcase_23 AC 17 ms
8,100 KB
testcase_24 AC 17 ms
8,008 KB
testcase_25 AC 370 ms
93,492 KB
testcase_26 AC 16 ms
8,000 KB
testcase_27 AC 16 ms
7,980 KB
testcase_28 AC 17 ms
7,996 KB
testcase_29 AC 16 ms
7,956 KB
testcase_30 AC 16 ms
8,104 KB
testcase_31 AC 17 ms
7,904 KB
testcase_32 AC 181 ms
50,832 KB
testcase_33 AC 755 ms
178,880 KB
testcase_34 AC 749 ms
178,792 KB
testcase_35 AC 346 ms
93,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
N, L = map(int, input().split())
max_interval = int(L//(N-1))+1

primes = set(range(7, max_interval, 6)).union(range(5, max_interval, 6))
if max_interval > 2:
    primes.add(2)
if max_interval > 3:
    primes.add(3)

du = primes.difference_update
for i in range(5, int(sqrt(max_interval))+1, 6):
    if i in primes:
        du(range(i*3, max_interval, i*2))
    if i+2 in primes:
        du(range(i*3+6, max_interval, i*2+4))

print((L+1)*len(primes)+(1-N)*sum(primes))
0