結果
| 問題 | 
                            No.826 連絡網
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hipopo
                         | 
                    
| 提出日時 | 2020-04-22 14:07:46 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 97 ms / 2,000 ms | 
| コード長 | 2,362 bytes | 
| コンパイル時間 | 1,662 ms | 
| コンパイル使用メモリ | 132,836 KB | 
| 最終ジャッジ日時 | 2025-01-09 22:29:10 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)
const double PI = acos(-1.0);
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}
template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}
template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }
template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }
const int MAX_V = 1000001;
int par[MAX_V];
int depth[MAX_V];
int num[MAX_V];
void init(int n) {
    for(int i = 0; i < n; i++) {
        par[i] = i;
        depth[i] = 0;
        num[i] = 1;
    }
}
int root(int x) {
    if (par[x] == x) return x;
    else return par[x] = root(par[x]);
}
void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    num[x] += num[y];
    num[y] = num[x];
    if (depth[x] < depth[y]) par[x] = y;
    else {
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}
bool same(int x, int y) {
    return root(x) == root(y);
}
int get_num(int x) {
    return num[root(x)];
}
int main() {
    int n, p;
    cin >> n >> p;
    init(n + 1);
    repr(u, 2, n + 1) {
        repr(i, 2, n + 1) {
            if (n < (ll)u * i) break;
            int v = u * i;
            unite(u, v);
        }
    }
    
    cout << get_num(p) << endl;
}
            
            
            
        
            
hipopo