結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー warm4C0warm4C0
提出日時 2021-08-29 19:52:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 1,490 ms
コンパイル使用メモリ 166,124 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 23:40:01
合計ジャッジ時間 3,277 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
6,812 KB
testcase_01 AC 51 ms
6,940 KB
testcase_02 AC 52 ms
6,944 KB
testcase_03 AC 52 ms
6,944 KB
testcase_04 AC 51 ms
6,940 KB
testcase_05 AC 50 ms
6,944 KB
testcase_06 AC 50 ms
6,940 KB
testcase_07 AC 51 ms
6,940 KB
testcase_08 AC 51 ms
6,944 KB
testcase_09 AC 51 ms
6,944 KB
testcase_10 AC 50 ms
6,944 KB
testcase_11 AC 52 ms
6,944 KB
testcase_12 AC 52 ms
6,940 KB
testcase_13 AC 51 ms
6,944 KB
testcase_14 AC 52 ms
6,944 KB
testcase_15 AC 51 ms
6,940 KB
testcase_16 AC 51 ms
6,940 KB
testcase_17 AC 53 ms
6,944 KB
testcase_18 AC 53 ms
6,940 KB
testcase_19 AC 51 ms
6,940 KB
testcase_20 AC 50 ms
6,944 KB
testcase_21 AC 51 ms
6,944 KB
testcase_22 AC 51 ms
6,944 KB
testcase_23 AC 50 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define MAX_LR (1000000)

using namespace std;

typedef long long ll;

int main() {
    ll l, r;
    bool is_prime_memo[MAX_LR + MAX_LR + 1 + 1];
    int ans = 0;

    scanf("%lld %lld", &l, &r);

    for (int i = 1; i <= MAX_LR + MAX_LR + 1; i++) {
        is_prime_memo[i] = true;
    }
    is_prime_memo[1] = false;
    for (int i = 2; i <= MAX_LR + MAX_LR + 1; i++) {
        for (int j = i + i; j <= MAX_LR + MAX_LR + 1; j+=i) {
            is_prime_memo[j] = false;
        }
    }

    for (ll i = l; i <= r; i++) {
        if (is_prime_memo[i]) {
            ans++;
        }
        if (i+1 <= r && is_prime_memo[i+i+1]) {
            ans++;
        }
    }

    printf("%d\n", ans);
    
    return 0;
}
0