結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー ytftytft
提出日時 2021-08-30 11:03:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 515 bytes
コンパイル時間 3,734 ms
コンパイル使用メモリ 336,908 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-05-02 13:25:55
合計ジャッジ時間 4,823 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 26 ms
10,624 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 24 ms
10,624 KB
testcase_13 AC 11 ms
7,168 KB
testcase_14 AC 18 ms
9,600 KB
testcase_15 AC 20 ms
9,728 KB
testcase_16 AC 9 ms
6,272 KB
testcase_17 AC 9 ms
6,528 KB
testcase_18 AC 10 ms
6,912 KB
testcase_19 AC 29 ms
10,112 KB
testcase_20 AC 14 ms
8,064 KB
testcase_21 AC 24 ms
11,008 KB
testcase_22 AC 23 ms
11,136 KB
testcase_23 AC 23 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

int main(){
    int L,R;
    cin>>L>>R;
    vector<int> isPrime(2*R,1);
    isPrime[1]=0;
    for(int i=2;i<2*R;++i){
        if(isPrime[i]){
            for(int j=i*2;j<2*R;j+=i){
                isPrime[j]=0;
            }
        }
    }
    int ans=0;
    for(int i=L;i<R;i++){
        ans+=isPrime[i];
        ans+=isPrime[2*i+1];
    }
    ans+=isPrime[R];
    cout<<ans<<endl;
}
0