結果

問題 No.826 連絡網
ユーザー leaf_1415leaf_1415
提出日時 2019-05-06 00:31:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 825 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 565 ms
コンパイル使用メモリ 61,240 KB
実行使用メモリ 124,152 KB
最終ジャッジ日時 2024-05-03 05:20:13
合計ジャッジ時間 8,878 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
50,176 KB
testcase_01 AC 21 ms
50,304 KB
testcase_02 AC 22 ms
50,432 KB
testcase_03 AC 27 ms
50,816 KB
testcase_04 AC 23 ms
50,816 KB
testcase_05 AC 20 ms
50,688 KB
testcase_06 AC 21 ms
50,688 KB
testcase_07 AC 21 ms
50,816 KB
testcase_08 AC 21 ms
50,560 KB
testcase_09 AC 23 ms
50,944 KB
testcase_10 AC 20 ms
50,304 KB
testcase_11 AC 22 ms
50,688 KB
testcase_12 AC 563 ms
103,644 KB
testcase_13 AC 207 ms
71,040 KB
testcase_14 AC 405 ms
89,800 KB
testcase_15 AC 45 ms
54,912 KB
testcase_16 AC 261 ms
76,524 KB
testcase_17 AC 201 ms
71,068 KB
testcase_18 AC 151 ms
66,240 KB
testcase_19 AC 659 ms
112,088 KB
testcase_20 AC 660 ms
110,720 KB
testcase_21 AC 23 ms
51,072 KB
testcase_22 AC 212 ms
71,440 KB
testcase_23 AC 285 ms
77,564 KB
testcase_24 AC 114 ms
61,776 KB
testcase_25 AC 825 ms
123,832 KB
testcase_26 AC 130 ms
64,264 KB
testcase_27 AC 593 ms
105,296 KB
testcase_28 AC 420 ms
92,304 KB
testcase_29 AC 199 ms
70,836 KB
testcase_30 AC 806 ms
124,152 KB
testcase_31 AC 249 ms
75,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

int n, p;
vector<int> fact[1000005];
bool prime[1000005];
vector<int> G[1000005];
bool used[1000005];

void dfs(int v)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i]]) continue;
		dfs(G[v][i]);
	}
}

int main(void)
{
	cin >> n >> p;
	
	for(int i = 2; i <= n; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j <= n; j+=i){
			prime[j] = true;
			fact[j].push_back(i);
		}
	}
	
	for(int i = 2; i <= n; i++){
		for(int j = 0; j < fact[i].size(); j++){
			G[i].push_back(fact[i][j]);
			G[fact[i][j]].push_back(i);
		}
	}
	
	dfs(p);
	
	int ans = 0;
	for(int i = 1; i <= n; i++) if(used[i]) ans++;
	cout << ans << endl;
	
	return 0;
}
0