結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー Hideaki ItoHideaki Ito
提出日時 2021-08-27 21:37:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,340 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 170,124 KB
実行使用メモリ 7,524 KB
最終ジャッジ日時 2024-05-01 01:55:03
合計ジャッジ時間 3,105 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,424 KB
testcase_01 AC 18 ms
7,420 KB
testcase_02 AC 44 ms
7,296 KB
testcase_03 AC 18 ms
7,420 KB
testcase_04 AC 17 ms
7,292 KB
testcase_05 AC 18 ms
7,296 KB
testcase_06 AC 18 ms
7,424 KB
testcase_07 AC 18 ms
7,296 KB
testcase_08 AC 18 ms
7,376 KB
testcase_09 AC 18 ms
7,364 KB
testcase_10 AC 18 ms
7,424 KB
testcase_11 AC 18 ms
7,220 KB
testcase_12 AC 42 ms
7,424 KB
testcase_13 AC 28 ms
7,420 KB
testcase_14 AC 29 ms
7,420 KB
testcase_15 AC 34 ms
7,296 KB
testcase_16 AC 23 ms
7,428 KB
testcase_17 AC 19 ms
7,424 KB
testcase_18 AC 20 ms
7,524 KB
testcase_19 AC 48 ms
7,292 KB
testcase_20 AC 26 ms
7,428 KB
testcase_21 AC 50 ms
7,300 KB
testcase_22 AC 18 ms
7,300 KB
testcase_23 AC 21 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

bool arr[2000005];
vector<ll> primes;
void Eratosthenes(int N) {
  for(int i=0; i<=N; i++) {
    arr[i] = true;
  }
  for(int i=2; i<=N; i++) {
    if(arr[i]) {
      for(int j=0; i*(j+2)<=N; j++) {
        arr[i*(j+2)] = false;
      }
    }
  }
  for(int i=2; i<=N; i++) {
    if(arr[i]) {
      primes.push_back(i);
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int l, r; cin >> l >> r;
  Eratosthenes(2000005);
  int ans = 0;
  ans += upper_bound(all(primes), r) - lower_bound(all(primes), l);
  for(int a=l; a<r; a++) {
    int b = a+1;
    int sum = a+b;
    auto itr = lower_bound(all(primes), sum);
    if(itr == primes.end()) continue;
    if(*itr == sum) ans++;
  }
  cout << ans << endk;
  return 0;
}
0