結果

問題 No.826 連絡網
ユーザー 0w1
提出日時 2020-11-15 02:51:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 478 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 198,348 KB
最終ジャッジ日時 2025-01-16 00:44:28
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, P; {
    cin >> N >> P;
  }

  vector<int> sz(N + 1, 1);
  vector<int> fa(N + 1); {
    iota(fa.begin(), fa.end(), 0);
  }
  function<int(int)> find = [&](int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); };
  function<void(int, int)> unite = [&](int x, int y) {
    int fx = find(x);
    int fy = find(y);
    if (fx == fy) return;
    sz[fx] += sz[fy];
    fa[fy] = fx;
  };

  vector<int> np(N + 1); {
    for (int i = 2; i <= N; ++i) {
      for (int j = i + i; j <= N; j += i) {
        unite(i, j);
      }
    }
  }

  cout << sz[find(P)] << endl;
}
0