結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー nawawannawawan
提出日時 2021-08-27 21:26:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 1,737 ms
コンパイル使用メモリ 201,812 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2024-05-01 01:34:41
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
10,956 KB
testcase_01 AC 17 ms
11,056 KB
testcase_02 AC 21 ms
10,996 KB
testcase_03 AC 18 ms
11,080 KB
testcase_04 AC 18 ms
10,988 KB
testcase_05 AC 18 ms
11,016 KB
testcase_06 AC 18 ms
10,860 KB
testcase_07 AC 18 ms
11,092 KB
testcase_08 AC 18 ms
11,064 KB
testcase_09 AC 18 ms
11,048 KB
testcase_10 AC 18 ms
10,860 KB
testcase_11 AC 18 ms
11,092 KB
testcase_12 AC 20 ms
11,000 KB
testcase_13 AC 19 ms
11,056 KB
testcase_14 AC 23 ms
10,992 KB
testcase_15 AC 20 ms
10,888 KB
testcase_16 AC 19 ms
10,860 KB
testcase_17 AC 18 ms
11,192 KB
testcase_18 AC 18 ms
11,080 KB
testcase_19 AC 21 ms
11,020 KB
testcase_20 AC 18 ms
11,060 KB
testcase_21 AC 24 ms
10,992 KB
testcase_22 AC 17 ms
11,060 KB
testcase_23 AC 18 ms
10,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int L, R;
    cin >> L >> R;
    vector<int> fac(2000020);
    iota(fac.begin(), fac.end(), 0);
    for(int i = 2; i < 2000020; i++){
        if(fac[i] != i) continue;
        int t = i;
        while(t < 2000020){
            fac[t] = i;
            t += i;
        }
    }
    int ans = 0;
    for(int i = L; i <= R; i++){
        if(i != 1 && fac[i] == i) ans++;
        if(i < R){
            if(fac[2 * i + 1] == 2 * i + 1) ans++;
        }
    }
    cout << ans << endl;
}
0