結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー 👑 KazunKazun
提出日時 2021-08-27 21:28:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 91,044 KB
最終ジャッジ日時 2024-05-01 01:39:35
合計ジャッジ時間 2,649 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,596 KB
testcase_01 AC 35 ms
54,024 KB
testcase_02 AC 87 ms
89,972 KB
testcase_03 AC 37 ms
53,416 KB
testcase_04 AC 37 ms
53,804 KB
testcase_05 AC 40 ms
52,960 KB
testcase_06 AC 45 ms
60,644 KB
testcase_07 AC 41 ms
59,252 KB
testcase_08 AC 42 ms
60,388 KB
testcase_09 AC 44 ms
61,864 KB
testcase_10 AC 45 ms
61,080 KB
testcase_11 AC 48 ms
62,420 KB
testcase_12 AC 86 ms
88,396 KB
testcase_13 AC 68 ms
78,092 KB
testcase_14 AC 80 ms
85,244 KB
testcase_15 AC 81 ms
87,284 KB
testcase_16 AC 63 ms
72,908 KB
testcase_17 AC 63 ms
75,816 KB
testcase_18 AC 66 ms
76,240 KB
testcase_19 AC 79 ms
86,832 KB
testcase_20 AC 71 ms
79,516 KB
testcase_21 AC 84 ms
90,072 KB
testcase_22 AC 86 ms
89,612 KB
testcase_23 AC 84 ms
91,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Sieve_of_Eratosthenes(N,mode=False):
    """Nまでのエラトステネスの篩を実行

    N:自然数
    mode:False->素数のリスト,True->素数かどうかのリスト
    (False->[2,3,5,...],True->[0,0,1,1,0,1,...])
    """

    if N==0:
        return [0]

    T=[1]*(N+1)
    T[0]=T[1]=0

    for x in range(4,N+1,2): T[x]=0
    for x in range(9,N+1,3): T[x]=0

    a=5
    Flag=0
    while a*a<=N:
        if T[a]:
            b=a*a
            c=2*a
            while b<=N:
                T[b]=0
                b+=c
        a+=2+2*Flag
        Flag^=1

    if mode:
        return T
    else:
        return [k for k in range(N+1) if T[k]]
#==================================================
L,R=map(int,input().split())
P=Sieve_of_Eratosthenes(2*R,False)

X=0
for p in P:
    if L<=p<=R:
        X+=1

for p in P:
    if p==2:
        continue

    a=(p-1)//2
    b=a+1

    if L<=a<=R and L<=b<=R and a!=b:
        X+=1

print(X)
0