結果

問題 No.826 連絡網
ユーザー hoyamaghoyamag
提出日時 2019-05-03 23:04:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,238 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 173,072 KB
実行使用メモリ 7,000 KB
最終ジャッジ日時 2023-08-15 18:26:23
合計ジャッジ時間 3,063 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,852 KB
testcase_01 AC 5 ms
6,736 KB
testcase_02 AC 4 ms
6,856 KB
testcase_03 AC 3 ms
6,904 KB
testcase_04 AC 3 ms
6,880 KB
testcase_05 AC 4 ms
6,856 KB
testcase_06 AC 4 ms
6,908 KB
testcase_07 AC 3 ms
6,904 KB
testcase_08 AC 3 ms
6,668 KB
testcase_09 AC 4 ms
6,964 KB
testcase_10 AC 4 ms
7,000 KB
testcase_11 AC 3 ms
6,708 KB
testcase_12 AC 12 ms
6,904 KB
testcase_13 AC 6 ms
6,904 KB
testcase_14 AC 9 ms
6,764 KB
testcase_15 AC 4 ms
6,684 KB
testcase_16 AC 8 ms
6,732 KB
testcase_17 AC 6 ms
6,884 KB
testcase_18 AC 5 ms
6,988 KB
testcase_19 AC 13 ms
6,696 KB
testcase_20 AC 14 ms
6,712 KB
testcase_21 AC 3 ms
6,860 KB
testcase_22 AC 6 ms
6,876 KB
testcase_23 AC 7 ms
6,684 KB
testcase_24 AC 4 ms
6,904 KB
testcase_25 AC 16 ms
6,984 KB
testcase_26 AC 5 ms
6,668 KB
testcase_27 AC 12 ms
6,696 KB
testcase_28 AC 10 ms
6,880 KB
testcase_29 AC 6 ms
6,968 KB
testcase_30 AC 15 ms
6,804 KB
testcase_31 AC 7 ms
6,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
std::map<long long, long long> primeFactorization(
    long long n) { /* prime factorization * nを素因数分解する */
  std::map<long long, long long> pf;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      ++pf[i];
    }
  }
  if (n > 1) {
    ++pf[n];
  }
  return pf;
}
int N, P;
const int MAX_N = 1e6;
VEC<int> used(MAX_N + 2, 0);
void dfs(int p) {
  if (used[p]) return;
  // DUMP(p);
  used[p] = true;
  int i = 2;
  while (p * i <= N) {
    used[p * i] = true;
    if (i > 1) dfs(i);
    ++i;
  }
}


int main() {
  cin >> N >> P;
  auto pf = primeFactorization(P);
  for (auto v : pf) {
    int q = v.first;
    dfs(q);
  }

  dfs(P);
  DUMP();
  int cnt = 0;
  REP(i, 1, N + 1) {
    if (used[i] == true) {
      // DUMP(i);
      ++cnt;
    }
  }
  cout << cnt << endl;

  return 0;
}
0