結果
| 問題 | No.826 連絡網 | 
| コンテスト | |
| ユーザー |  risujiroh | 
| 提出日時 | 2019-05-03 21:34:34 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 61 ms / 2,000 ms | 
| コード長 | 828 bytes | 
| コンパイル時間 | 1,806 ms | 
| コンパイル使用メモリ | 168,396 KB | 
| 実行使用メモリ | 7,168 KB | 
| 最終ジャッジ日時 | 2024-11-24 02:15:05 | 
| 合計ジャッジ時間 | 3,473 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, p; cin >> n >> p;
  UnionFind uf(n + 1);
  for (int d = 2; d <= n; ++d) {
    for (int i = 2 * d; i <= n; i += d) {
      uf.unite(d, i);
    }
  }
  cout << uf.size(p) << '\n';
}
            
            
            
        