結果

問題 No.1661 Sum is Prime (Hard Version)
ユーザー convexineqconvexineq
提出日時 2021-08-28 20:51:57
言語 PyPy3
(7.3.13)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 668 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 106,700 KB
最終ジャッジ日時 2023-08-14 03:17:00
合計ジャッジ時間 26,686 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,704 KB
testcase_01 AC 72 ms
71,660 KB
testcase_02 AC 2,089 ms
97,348 KB
testcase_03 AC 71 ms
71,124 KB
testcase_04 AC 72 ms
71,832 KB
testcase_05 AC 72 ms
71,880 KB
testcase_06 AC 76 ms
76,212 KB
testcase_07 AC 71 ms
71,836 KB
testcase_08 AC 75 ms
75,944 KB
testcase_09 AC 76 ms
76,424 KB
testcase_10 AC 78 ms
76,160 KB
testcase_11 AC 76 ms
76,244 KB
testcase_12 AC 1,842 ms
95,788 KB
testcase_13 AC 1,794 ms
95,356 KB
testcase_14 AC 2,040 ms
97,680 KB
testcase_15 AC 2,672 ms
102,484 KB
testcase_16 AC 2,197 ms
98,492 KB
testcase_17 AC 2,022 ms
97,200 KB
testcase_18 AC 847 ms
85,520 KB
testcase_19 AC 1,478 ms
93,192 KB
testcase_20 AC 912 ms
87,040 KB
testcase_21 AC 1,738 ms
92,156 KB
testcase_22 AC 1,326 ms
89,384 KB
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)
if L < R: ans += prime_counting(2*R-1) - prime_counting(2*L)
print(ans)
0