結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー SSRSSSRS
提出日時 2021-08-27 21:23:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 1,315 ms
コンパイル使用メモリ 168,776 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 01:29:41
合計ジャッジ時間 2,261 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,816 KB
testcase_01 AC 11 ms
6,944 KB
testcase_02 AC 14 ms
6,940 KB
testcase_03 AC 14 ms
6,944 KB
testcase_04 AC 13 ms
6,944 KB
testcase_05 AC 13 ms
6,940 KB
testcase_06 AC 13 ms
6,940 KB
testcase_07 AC 12 ms
6,940 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 13 ms
6,940 KB
testcase_10 AC 12 ms
6,940 KB
testcase_11 AC 12 ms
6,944 KB
testcase_12 AC 14 ms
6,944 KB
testcase_13 AC 13 ms
6,944 KB
testcase_14 AC 13 ms
6,944 KB
testcase_15 AC 13 ms
6,940 KB
testcase_16 AC 12 ms
6,944 KB
testcase_17 AC 13 ms
6,940 KB
testcase_18 AC 12 ms
6,940 KB
testcase_19 AC 15 ms
6,944 KB
testcase_20 AC 13 ms
6,940 KB
testcase_21 AC 15 ms
6,940 KB
testcase_22 AC 12 ms
6,940 KB
testcase_23 AC 12 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000002;
int main(){
  vector<bool> prime(MAX, true);
  prime[1] = false;
  for (int i = 2; i < MAX; i++){
    if (prime[i]){
      for (int j = i * 2; j < MAX; j += i){
        prime[j] = false;
      }
    }
  }
  int L, R;
  cin >> L >> R;
  int ans = 0;
  for (int i = L; i <= R; i++){
    if (prime[i]){
      ans++;
    }
  }
  for (int i = L; i < R; i++){
    if (prime[i + (i + 1)]){
      ans++;
    }
  }
  cout << ans << endl;
}
0