結果

問題 No.1661 Sum is Prime (Hard Version)
ユーザー vwxyzvwxyz
提出日時 2022-10-04 02:36:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,319 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 20,724 KB
最終ジャッジ日時 2023-08-27 23:31:12
合計ジャッジ時間 30,442 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,260 KB
testcase_01 AC 16 ms
8,076 KB
testcase_02 AC 2,379 ms
20,544 KB
testcase_03 WA -
testcase_04 AC 15 ms
8,068 KB
testcase_05 AC 16 ms
8,240 KB
testcase_06 AC 15 ms
8,060 KB
testcase_07 AC 15 ms
8,044 KB
testcase_08 AC 16 ms
8,076 KB
testcase_09 AC 16 ms
8,080 KB
testcase_10 AC 16 ms
8,044 KB
testcase_11 AC 16 ms
8,176 KB
testcase_12 AC 2,085 ms
18,676 KB
testcase_13 AC 2,036 ms
18,340 KB
testcase_14 AC 2,331 ms
18,476 KB
testcase_15 TLE -
testcase_16 AC 2,484 ms
20,188 KB
testcase_17 AC 2,311 ms
19,644 KB
testcase_18 AC 919 ms
15,600 KB
testcase_19 AC 1,680 ms
16,832 KB
testcase_20 AC 1,005 ms
15,316 KB
testcase_21 AC 1,934 ms
20,604 KB
testcase_22 TLE -
testcase_23 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

def Primes_Count(N):
    if N<2:
        return 0
    v=int(N**0.5)+1
    smalls=[i//2 for i in range(1,v+1)]
    smalls[1]=0
    s=v//2
    roughs=[2*i+1 for i in range(s)]
    larges=[(N//(2*i+1)+1)//2 for i in range(s)]
    skip=[False]*v
    pc=0
    for p in range(3,v):
        if smalls[p]<=smalls[p-1]:
            continue
        q=p*p
        pc+=1
        if q*q>N:
            break
        skip[p]=True
        for i in range(q,v,2*p):
            skip[i]=True
        ns=0
        for k in range(s):
            i=roughs[k]
            if skip[i]:
                continue
            d=i*p
            larges[ns]=larges[k]-(larges[smalls[d]-pc] if d<v else smalls[N//d])+pc
            roughs[ns]=i
            ns+=1
        s=ns
        for j in range((v-1)//p,p-1,-1):
            c=smalls[j]-pc
            e=min((j+1)*p,v)
            for i in range(j*p,e):
                smalls[i]-=c
    for k in range(1,s):
        m=N//roughs[k]
        s=larges[k]-(pc+k-1)
        for l in range(1,k):
            p=roughs[l]
            if p*p>m:
                break
            s-=smalls[m//p]-(pc+l-1)
        larges[0]-=s
    return larges[0]

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