結果
| 問題 | No.826 連絡網 | 
| コンテスト | |
| ユーザー |  gazelle | 
| 提出日時 | 2019-05-03 22:55:34 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 50 ms / 2,000 ms | 
| コード長 | 1,595 bytes | 
| コンパイル時間 | 841 ms | 
| コンパイル使用メモリ | 115,788 KB | 
| 最終ジャッジ日時 | 2025-01-07 03:28:23 | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using lint = long long;
using ld = long double;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(lint i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
class union_find {
public:
	union_find(int n)
	: par_(n, -1)
	{}
	void init(int n) {
		par_.assign(n, -1);
	}
	int root(int x) {
		return par_[x] < 0 ? x : par_[x] = root(par_[x]);
	}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if(x == y) {
			return false;
		} else {
			if(par_[x] < par_[y]) {
				par_[x] += par_[y];
				par_[y] = x;
			} else {
				par_[y] += par_[x];
				par_[x] = y;
			}
			return true;
		}
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int size(int x) {
		return -par_[root(x)];
	}
private:
	std::vector<int> par_;
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, p;
	cin >> n >> p;
	union_find uf(n);
	for(int i = 2; i <= n; i++) {
		for(int j = 1; i * j <= n; j++) {
			uf.unite(i - 1, i * j - 1);
		}
	}
	cout << (int)uf.size(p - 1) << endl;
	return 0;
}
/* --------------------------------------- */
            
            
            
        