結果

問題 No.1661 Sum is Prime (Hard Version)
ユーザー 👑 KazunKazun
提出日時 2021-08-27 21:58:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,173 ms / 3,000 ms
コード長 953 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 83,024 KB
最終ジャッジ日時 2023-08-13 08:53:10
合計ジャッジ時間 11,962 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,848 KB
testcase_01 AC 75 ms
71,580 KB
testcase_02 AC 755 ms
82,052 KB
testcase_03 AC 74 ms
71,572 KB
testcase_04 AC 75 ms
71,612 KB
testcase_05 AC 76 ms
71,816 KB
testcase_06 AC 83 ms
76,532 KB
testcase_07 AC 77 ms
71,600 KB
testcase_08 AC 83 ms
76,696 KB
testcase_09 AC 82 ms
76,336 KB
testcase_10 AC 85 ms
76,384 KB
testcase_11 AC 85 ms
76,480 KB
testcase_12 AC 673 ms
81,580 KB
testcase_13 AC 658 ms
81,384 KB
testcase_14 AC 734 ms
81,784 KB
testcase_15 AC 937 ms
82,744 KB
testcase_16 AC 789 ms
81,972 KB
testcase_17 AC 728 ms
81,644 KB
testcase_18 AC 356 ms
79,820 KB
testcase_19 AC 558 ms
81,144 KB
testcase_20 AC 378 ms
79,692 KB
testcase_21 AC 638 ms
81,320 KB
testcase_22 AC 1,173 ms
83,024 KB
testcase_23 AC 1,126 ms
82,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#Thanks for https://judge.yosupo.jp/submission/33263
from math import sqrt
def prime_counting(n):
    if n<=1:
        return 0

    n2 = int(n ** 0.5)
    ndn2 = int(n / n2)
    hl = [0] * ndn2
    for i in range(1, ndn2):
        hl[i] = int(n / i) - 1
    hs = list(range(-1, n2))
    pi = 0
    for x in range(2, n2 + 1):
        if hs[x] == hs[x - 1]:
            continue
        x2 = x * x
        imax = min(ndn2, int(n / x2) + 1)
        ix = x
        for i in range(1, imax):
            if ix < ndn2:
                hl[i] -= hl[ix]
            else:
                hl[i] -= hs[int(n / ix)]
            hl[i] += pi
            ix += x
        for k in range(n2, x2 - 1, -1):
            hs[k] -= hs[int(k / x)] - pi
        pi += 1
    return hl[1]
#==================================================
L,R=map(int,input().split())

alpha=prime_counting(R)-prime_counting(L-1)
beta =prime_counting(2*R)-prime_counting(2*L)

print(alpha+beta)
0