結果

問題 No.826 連絡網
ユーザー chocorusk
提出日時 2019-05-03 21:38:28
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 97,144 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-11-24 02:15:28
合計ジャッジ時間 3,008 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int sz[1000010];
int par[1000010];
int rk[1000010];
void init(int n){
	for(int i=0; i<n; i++){
		par[i]=i;
        rk[i]=0;
        sz[i]=1;
	}
}
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(rk[x]<rk[y]){
		par[x]=y;
        sz[y]+=sz[x];
	}else{
		par[y]=x;
        sz[x]+=sz[y];
		if(rk[x]==rk[y]) rk[x]++;
	}
}
int main()
{
    int n, p; cin>>n>>p;
    init(n+1);
    for(int i=2; i<=n; i++){
        for(int j=i; j+i<=n; j+=i){
            unite(j, j+i);
        }
    }
    cout<<sz[find(p)]<<endl;
    return 0;
}
0