結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー monnumonnu
提出日時 2021-08-27 22:58:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 3,702 ms
コンパイル使用メモリ 228,412 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-13 10:27:49
合計ジャッジ時間 5,346 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
4,380 KB
testcase_01 AC 18 ms
4,424 KB
testcase_02 AC 21 ms
4,384 KB
testcase_03 AC 18 ms
4,384 KB
testcase_04 AC 18 ms
4,452 KB
testcase_05 AC 18 ms
4,500 KB
testcase_06 AC 18 ms
4,440 KB
testcase_07 AC 17 ms
4,448 KB
testcase_08 AC 18 ms
4,388 KB
testcase_09 AC 18 ms
4,384 KB
testcase_10 AC 18 ms
4,384 KB
testcase_11 AC 18 ms
4,384 KB
testcase_12 AC 21 ms
4,432 KB
testcase_13 AC 19 ms
4,480 KB
testcase_14 AC 19 ms
4,448 KB
testcase_15 AC 20 ms
4,380 KB
testcase_16 AC 18 ms
4,440 KB
testcase_17 AC 19 ms
4,380 KB
testcase_18 AC 18 ms
4,380 KB
testcase_19 AC 21 ms
4,424 KB
testcase_20 AC 18 ms
4,384 KB
testcase_21 AC 22 ms
4,380 KB
testcase_22 AC 18 ms
4,500 KB
testcase_23 AC 18 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 2000000
#define MOD 998244353
#define INF 1000000000

vector<int> p;
vector<bool> p_table(MAX+1,true);
void prime(){
  p_table.at(0)=false,p_table.at(1)=false;
  for(int i=2;i<=MAX;i++){
    if(p_table.at(i)){
      p.push_back(i);
      for(int j=2;i*j<=MAX;j++){
        p_table.at(i*j)=false;
      }
    }
  }
}

int main(){
  ll L,R;
  cin>>L>>R;

  prime();
  int ans=0;
  for(int i=L;i<=R;i++){
    if(p_table[i]){
      ans++;
    }
  }
  for(int i=L;i<R;i++){
    if(p_table[i+(i+1)]){
      ans++;
    }
  }
  cout<<ans<<'\n';
}
0