結果

問題 No.826 連絡網
ユーザー むらためむらため
提出日時 2019-05-22 02:46:48
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 3,924 ms
コンパイル使用メモリ 132,384 KB
実行使用メモリ 4,532 KB
最終ジャッジ日時 2023-08-20 12:25:31
合計ジャッジ時間 2,932 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,440 KB
testcase_01 AC 4 ms
4,468 KB
testcase_02 AC 4 ms
4,424 KB
testcase_03 AC 4 ms
4,384 KB
testcase_04 AC 4 ms
4,384 KB
testcase_05 AC 4 ms
4,508 KB
testcase_06 AC 3 ms
4,532 KB
testcase_07 AC 4 ms
4,528 KB
testcase_08 AC 4 ms
4,452 KB
testcase_09 AC 4 ms
4,488 KB
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 4 ms
4,532 KB
testcase_12 AC 4 ms
4,384 KB
testcase_13 AC 4 ms
4,528 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 4 ms
4,384 KB
testcase_18 AC 4 ms
4,388 KB
testcase_19 AC 3 ms
4,384 KB
testcase_20 AC 4 ms
4,384 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 4 ms
4,384 KB
testcase_23 AC 4 ms
4,508 KB
testcase_24 AC 3 ms
4,532 KB
testcase_25 AC 4 ms
4,388 KB
testcase_26 AC 4 ms
4,388 KB
testcase_27 AC 4 ms
4,484 KB
testcase_28 AC 3 ms
4,448 KB
testcase_29 AC 4 ms
4,384 KB
testcase_30 AC 4 ms
4,448 KB
testcase_31 AC 4 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include "bits/stdc++.h"

using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define ALL(a) begin(a), end(a)
#define let const auto

bool isNotPrimes[1000010];
void calcIsNotPrimes() {
  isNotPrimes[0] = true;
  isNotPrimes[1] = true;
  for (int i = 2; i * i < 1000010; i++) {
    if (isNotPrimes[i]) continue;
    for (int j = i * 2; j < 1000010; j += i) isNotPrimes[j] = true;
  }
}
int scan() {
  int result = 0;
  while (true) {
    auto k = getchar_unlocked();
    if (k < '0' || k > '9') return result;
    result = 10 * result + k - '0';
  }
}

signed main() {
  calcIsNotPrimes();
  let n = scan();
  let p = scan();
  if (p == 1 || (p >= n / 2 && !isNotPrimes[p])) {
    printf("1\n");
    return 0;
  }
  int ans = n / 2 - 1;
  FOR(i, n / 2 + 1, n + 1) {
    if (isNotPrimes[i]) ans += 1;
  }
  printf("%lld", ans);
}
0