結果

問題 No.1661 Sum is Prime (Hard Version)
ユーザー convexineqconvexineq
提出日時 2021-08-28 20:48:01
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 657 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 107,636 KB
最終ジャッジ日時 2023-08-14 03:16:31
合計ジャッジ時間 28,282 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,616 KB
testcase_01 AC 70 ms
71,804 KB
testcase_02 AC 2,063 ms
97,552 KB
testcase_03 WA -
testcase_04 AC 70 ms
71,784 KB
testcase_05 AC 69 ms
71,876 KB
testcase_06 AC 75 ms
76,248 KB
testcase_07 AC 70 ms
71,832 KB
testcase_08 AC 74 ms
76,148 KB
testcase_09 AC 74 ms
76,156 KB
testcase_10 AC 75 ms
76,048 KB
testcase_11 AC 77 ms
76,236 KB
testcase_12 AC 1,819 ms
96,208 KB
testcase_13 AC 1,783 ms
95,688 KB
testcase_14 AC 2,018 ms
97,808 KB
testcase_15 AC 2,666 ms
102,260 KB
testcase_16 AC 2,164 ms
98,584 KB
testcase_17 AC 1,991 ms
96,956 KB
testcase_18 AC 834 ms
85,412 KB
testcase_19 AC 1,467 ms
93,172 KB
testcase_20 AC 900 ms
87,152 KB
testcase_21 AC 1,714 ms
92,128 KB
testcase_22 TLE -
testcase_23 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def prime_counting(n):
    if n <= 1: return 0
    r = int(n**0.5)
    assert r*r <= n < (r+1)**2
    V = [0] + [n//i for i in range(1,r+1)] + list(range(n//r-1,0,-1))
    S = [i-1 for i in V]
    for p in range(2,r+1):
        if S[-p] > S[-p+1]:  # p is prime
            sp = S[-p+1]  # number of primes smaller than p
            p2 = p*p
            for i in range(1,2*r+1):
                v = V[i]
                if v < p2: break
                S[i] -= (S[-(v//p) if v//p <= r else i*p] - sp)
    return S[1]

L,R = map(int,input().split())
ans = prime_counting(R) - prime_counting(L-1)
ans += prime_counting(2*R-1) - prime_counting(2*L)
print(ans)
0