結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー batsumarubatsumaru
提出日時 2021-08-27 22:01:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 167,280 KB
実行使用メモリ 10,804 KB
最終ジャッジ日時 2023-08-13 08:57:23
合計ジャッジ時間 2,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 17 ms
10,400 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 18 ms
10,508 KB
testcase_13 AC 9 ms
6,892 KB
testcase_14 AC 13 ms
9,348 KB
testcase_15 AC 15 ms
9,520 KB
testcase_16 AC 8 ms
5,848 KB
testcase_17 AC 8 ms
6,432 KB
testcase_18 AC 8 ms
6,576 KB
testcase_19 AC 17 ms
9,844 KB
testcase_20 AC 11 ms
7,772 KB
testcase_21 AC 18 ms
10,804 KB
testcase_22 AC 17 ms
10,700 KB
testcase_23 AC 17 ms
10,800 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