結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー 👑 NachiaNachia
提出日時 2021-08-27 21:23:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 692 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 76,792 KB
実行使用メモリ 11,000 KB
最終ジャッジ日時 2023-08-13 07:47:04
合計ジャッジ時間 1,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 15 ms
10,816 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 15 ms
10,456 KB
testcase_13 AC 8 ms
6,996 KB
testcase_14 AC 13 ms
9,496 KB
testcase_15 AC 12 ms
9,392 KB
testcase_16 AC 6 ms
5,884 KB
testcase_17 AC 6 ms
6,412 KB
testcase_18 AC 7 ms
6,660 KB
testcase_19 AC 15 ms
10,040 KB
testcase_20 AC 10 ms
7,896 KB
testcase_21 AC 16 ms
11,000 KB
testcase_22 AC 14 ms
10,816 KB
testcase_23 AC 15 ms
10,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)




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

  i64 ans = 0;
  for(int i=L; i<=R; i++) ans += sieve[i];
  for(int i=L; i<R; i++) ans += sieve[i+i+1];
  cout << ans << endl;
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;




0