結果

問題 No.826 連絡網
ユーザー hipopohipopo
提出日時 2020-04-22 14:07:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 2,362 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 136,356 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2024-04-19 14:52:44
合計ジャッジ時間 3,356 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 50 ms
12,160 KB
testcase_13 AC 17 ms
7,040 KB
testcase_14 AC 35 ms
9,856 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 22 ms
7,808 KB
testcase_17 AC 18 ms
7,040 KB
testcase_18 AC 12 ms
6,272 KB
testcase_19 AC 56 ms
13,440 KB
testcase_20 AC 56 ms
13,312 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 19 ms
7,040 KB
testcase_23 AC 23 ms
7,936 KB
testcase_24 AC 9 ms
5,504 KB
testcase_25 AC 73 ms
15,104 KB
testcase_26 AC 11 ms
6,016 KB
testcase_27 AC 52 ms
12,544 KB
testcase_28 AC 38 ms
10,496 KB
testcase_29 AC 17 ms
6,912 KB
testcase_30 AC 72 ms
15,360 KB
testcase_31 AC 22 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0