結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー batsumarubatsumaru
提出日時 2021-08-27 22:01:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 1,802 ms
コンパイル使用メモリ 167,752 KB
実行使用メモリ 11,068 KB
最終ジャッジ日時 2024-05-01 02:33:49
合計ジャッジ時間 2,513 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 18 ms
10,828 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 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 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 18 ms
10,648 KB
testcase_13 AC 10 ms
7,184 KB
testcase_14 AC 14 ms
9,664 KB
testcase_15 AC 16 ms
9,728 KB
testcase_16 AC 7 ms
6,144 KB
testcase_17 AC 7 ms
6,656 KB
testcase_18 AC 8 ms
6,912 KB
testcase_19 AC 16 ms
10,112 KB
testcase_20 AC 10 ms
7,956 KB
testcase_21 AC 19 ms
11,060 KB
testcase_22 AC 18 ms
10,992 KB
testcase_23 AC 16 ms
11,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

vector<int> Eratosthenes(ll n) {
  vector<int> res(n + 1, 1);
  res[0] = res[1] = 0;
  for (ll i = 2; i * i <= n; i++)
    if (res[i]) {
      for (ll j = 2; i * j <= n; j++) res[i * j] = 0;
    }
  return res;
}

int main() {
  ll l, r;
  cin >> l >> r;
  auto v = Eratosthenes(2 * r);
  ll ans = 0;
  FOR(i, l, r + 1) {
    if (v[i]) {
      ans++;
    }
  }
  FOR(i, 2 * l + 1, 2 * r) {
    if (v[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
0