結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー abc3abc3
提出日時 2021-08-27 23:41:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 202,996 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-05-01 04:27:41
合計ジャッジ時間 3,287 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 23 ms
10,680 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 22 ms
10,496 KB
testcase_13 AC 13 ms
7,164 KB
testcase_14 AC 20 ms
9,596 KB
testcase_15 AC 20 ms
9,776 KB
testcase_16 AC 9 ms
6,944 KB
testcase_17 AC 12 ms
6,940 KB
testcase_18 AC 11 ms
6,944 KB
testcase_19 AC 22 ms
10,096 KB
testcase_20 AC 15 ms
8,000 KB
testcase_21 AC 24 ms
11,008 KB
testcase_22 AC 29 ms
10,948 KB
testcase_23 AC 25 ms
10,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=998244353;

    void solve(){
        int l,r;
        cin>>l>>r;
        vector<int>seen(2*r+5);
        seen[1]=1;
        for(int i=2;i<=2*r+1;i++){
            if(seen[i]){continue;}
            for(int j=i*2;j<=2*r+1;j+=i){
                seen[j]=1;
            }
        }
        int cnt=0;
        for(int i=l;i<=r;i++){
            if(!seen[i]){cnt++;}
            if(i<r&&!seen[i*2+1]){cnt++;}
        }
        cout<<cnt<<endl;
    }  

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve();
        
        return 0;
    }
0