結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー playerplayer
提出日時 2023-12-23 16:59:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 85,572 KB
最終ジャッジ日時 2023-12-23 16:59:06
合計ジャッジ時間 4,560 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
82,956 KB
testcase_01 AC 113 ms
82,956 KB
testcase_02 AC 135 ms
85,568 KB
testcase_03 AC 146 ms
82,956 KB
testcase_04 AC 136 ms
82,956 KB
testcase_05 AC 118 ms
82,956 KB
testcase_06 AC 117 ms
85,572 KB
testcase_07 AC 116 ms
82,956 KB
testcase_08 AC 115 ms
82,956 KB
testcase_09 AC 115 ms
82,956 KB
testcase_10 AC 116 ms
82,956 KB
testcase_11 AC 121 ms
85,572 KB
testcase_12 AC 155 ms
85,568 KB
testcase_13 AC 126 ms
85,568 KB
testcase_14 AC 127 ms
85,568 KB
testcase_15 AC 128 ms
85,568 KB
testcase_16 AC 126 ms
85,568 KB
testcase_17 AC 125 ms
85,568 KB
testcase_18 AC 120 ms
85,568 KB
testcase_19 AC 129 ms
85,568 KB
testcase_20 AC 123 ms
85,568 KB
testcase_21 AC 155 ms
85,568 KB
testcase_22 AC 117 ms
82,956 KB
testcase_23 AC 123 ms
85,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Eratosthenes(N):
    # 素数であるかの判定リスト
    IsPrime = [True] * (N + 1)
    # i=2,3,4,...
    i = 2
    # i≤√Nまで⇔i^2≤Nまで
    while i**2 <= N:
        # iが素数でなければ
        if IsPrime[i] == False:
            # 次のiへ
            i += 1
            continue
        # k=2,3,4,...
        k = 2
        while i * k <= N:
            # iの倍数は素数でない
            IsPrime[i * k] = False
            # 次のkへ
            k += 1
        # 次のkへ
        i += 1
    return IsPrime


l, r = map(int, input().split())

lis = Eratosthenes(3 * 10**6)

cnt = 0
for a in range(l, r + 1):
    b = a
    if lis[(a + b) // 2]:
        if not (a == b == 1):
            cnt += 1
            # print(a, b)

    b = a + 1
    if b > r:
        continue
    if (a + b) % 2 == 1 or a + b == 2:
        if lis[a + b]:
            if not (a == b == 1):
                cnt += 1
                # print(a, b)

print(cnt)
0