結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー nawawannawawan
提出日時 2021-08-27 21:25:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 596 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 200,464 KB
実行使用メモリ 11,024 KB
最終ジャッジ日時 2023-08-13 07:49:19
合計ジャッジ時間 3,638 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
11,024 KB
testcase_01 AC 25 ms
10,712 KB
testcase_02 AC 27 ms
10,764 KB
testcase_03 AC 25 ms
10,764 KB
testcase_04 AC 26 ms
10,720 KB
testcase_05 AC 24 ms
10,764 KB
testcase_06 AC 27 ms
10,764 KB
testcase_07 AC 26 ms
10,724 KB
testcase_08 AC 26 ms
10,724 KB
testcase_09 AC 25 ms
10,764 KB
testcase_10 AC 26 ms
10,824 KB
testcase_11 AC 27 ms
10,836 KB
testcase_12 AC 28 ms
10,844 KB
testcase_13 AC 26 ms
10,716 KB
testcase_14 AC 26 ms
10,832 KB
testcase_15 AC 27 ms
10,932 KB
testcase_16 AC 25 ms
10,972 KB
testcase_17 AC 25 ms
11,016 KB
testcase_18 AC 25 ms
10,836 KB
testcase_19 AC 26 ms
10,972 KB
testcase_20 AC 26 ms
10,756 KB
testcase_21 AC 28 ms
10,836 KB
testcase_22 AC 24 ms
10,896 KB
testcase_23 AC 24 ms
10,720 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