結果

問題 No.826 連絡網
ユーザー むらため
提出日時 2019-05-22 02:46:48
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 2,614 ms
コンパイル使用メモリ 163,144 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 14:08:02
合計ジャッジ時間 3,255 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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