結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー Carpenters-Cat
提出日時 2021-08-27 21:27:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 551 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 168,596 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-21 00:50:20
合計ジャッジ時間 2,792 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main () {
    int L, R;
    cin >> L >> R;
    vector<bool> sosuu((R + 1) * 2, true);
    sosuu[0] = sosuu[1] = false;
    for (int i = 2; i < (R + 1) * 2; i ++) {
        if (sosuu[i]) {
            for (int j = 2; j * i < (R + 1) * 2; j ++) {
                sosuu[i * j] = false;
            }
        }
    }
    int ans = 0;
    for (int i = L; i <= R; i ++) {
        ans += (int)sosuu[i];
        if (i > L) {
            ans += (int)sosuu[i * 2 - 1];
        }
    }
    cout << ans << endl;
}
0