結果

問題 No.1661 Sum is Prime (Hard Version)
ユーザー tassei903tassei903
提出日時 2021-08-27 22:49:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 857 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 262,288 KB
最終ジャッジ日時 2024-05-01 03:36:54
合計ジャッジ時間 4,885 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
61,040 KB
testcase_01 AC 36 ms
53,992 KB
testcase_02 AC 2,916 ms
199,404 KB
testcase_03 WA -
testcase_04 AC 35 ms
52,536 KB
testcase_05 AC 35 ms
54,428 KB
testcase_06 AC 38 ms
59,752 KB
testcase_07 AC 35 ms
52,692 KB
testcase_08 AC 39 ms
58,672 KB
testcase_09 AC 37 ms
59,928 KB
testcase_10 AC 38 ms
59,760 KB
testcase_11 AC 38 ms
59,596 KB
testcase_12 AC 2,601 ms
174,276 KB
testcase_13 AC 2,530 ms
174,564 KB
testcase_14 AC 2,972 ms
181,580 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 AC 2,755 ms
189,264 KB
testcase_18 AC 1,180 ms
115,372 KB
testcase_19 AC 1,906 ms
151,660 KB
testcase_20 AC 1,246 ms
114,304 KB
testcase_21 AC 2,580 ms
175,872 KB
testcase_22 TLE -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################



import math

def pi(n):
    if n<=1:
        return 0
    m = int(math.sqrt(n))
    keys = [n // i for i in range(1, m + 1)]
    keys += range(keys[-1] - 1, 0, -1)
    h = {i : i - 1 for i in keys}
    for i in range(2, m + 1):
        if h[i] > h[i - 1]:
            hp = h[i - 1]
            i2 = i * i
            for j in keys:
                if j < i2: break
                h[j] -= h[j // i] - hp

    return h[n]

L,R = na()
print(pi(R)-pi(L-1)+pi(2*R-1)-pi(2*L))
0