結果
| 問題 | No.826 連絡網 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-02-10 02:57:51 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 28 ms / 2,000 ms | 
| コード長 | 814 bytes | 
| コンパイル時間 | 1,456 ms | 
| コンパイル使用メモリ | 171,304 KB | 
| 実行使用メモリ | 11,224 KB | 
| 最終ジャッジ日時 | 2024-07-07 11:50:52 | 
| 合計ジャッジ時間 | 2,764 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nax = 1e6 + 7;
vector<bool>prime(nax, true);
vector<int>par(nax);
vector<int>s(nax);
int get(int x) {
	if (x == par[x])return x;
	return (par[x] = get(par[x]));
}
bool modify(int x, int y) {
	x = get(x);
	y = get(y);
	if (x == y)return true;
	if (s[y] > s[x]) swap(x, y);
	par[y] = x;
	s[x] += s[y];
	return false;
}
void prepare(int n) {
	for (int i = 2; i <= n; i++) {
		if (prime[i]) {
			for (int j = 2; (j * i) <= n; j++) {
				prime[j * i] = false;
				modify(i * j, i);
				// cout << i << " " << i*j << endl;
			}
		}
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, node;
	cin >> n >> node;
	iota(par.begin(), par.end(), 0);
	fill(s.begin(), s.end(), 1);
	prepare(n);
	cout << s[get(node)] << endl;
}
            
            
            
        