結果
| 問題 | No.826 連絡網 | 
| コンテスト | |
| ユーザー |  polyomino_24 | 
| 提出日時 | 2019-05-03 22:15:02 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 29 ms / 2,000 ms | 
| コード長 | 2,139 bytes | 
| コンパイル時間 | 1,226 ms | 
| コンパイル使用メモリ | 124,140 KB | 
| 最終ジャッジ日時 | 2025-01-07 03:26:32 | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
 class UnionFind {
 private:
     int sz;
     vector<int> par, size_;
 public:
     UnionFind(){}
     UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
         iota(par.begin(), par.end(), 0);
     }
     int find(int x){
         if(par[x] == x) return x;
         else return par[x] = find(par[x]);
     }
     void unite(int x,int y){
         x = find(x), y = find(y);
         if(x == y) return;
         if(size_[x] < size_[y]) swap(x,y);
         par[y] = x;
         size_[x] += size_[y];
     }
     int size(int x){
         x = find(x);
         return size_[x];
     }
     bool same(int x,int y){
         return find(x) == find(y);
     }
 };
bool p[1000005];
int main(){
    int n, a;
    cin >> n >> a;
    UnionFind uf(n + 1);
    for(int i = 1; i <= n; i++){
        p[i] = true;
    }
    for(int i = 2; i <= n; i++){
        if(p[i]){
            for(int j = i * 2; j <= n; j+=i){
                p[j] = false;
                uf.unite(i,j);
            }
        }
    }
    cout << uf.size(a) << endl;
}
            
            
            
        