結果

問題 No.1059 素敵な集合
ユーザー HaaHaa
提出日時 2020-05-28 13:39:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 171,692 KB
実行使用メモリ 59,772 KB
最終ジャッジ日時 2023-09-30 15:38:30
合計ジャッジ時間 4,096 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,936 KB
testcase_01 AC 416 ms
59,772 KB
testcase_02 AC 22 ms
11,688 KB
testcase_03 AC 5 ms
8,020 KB
testcase_04 AC 5 ms
7,748 KB
testcase_05 AC 5 ms
7,936 KB
testcase_06 AC 19 ms
11,232 KB
testcase_07 AC 20 ms
11,112 KB
testcase_08 AC 26 ms
12,576 KB
testcase_09 AC 7 ms
8,792 KB
testcase_10 AC 46 ms
16,700 KB
testcase_11 AC 20 ms
11,548 KB
testcase_12 AC 11 ms
9,580 KB
testcase_13 AC 49 ms
15,968 KB
testcase_14 AC 5 ms
8,508 KB
testcase_15 AC 133 ms
24,336 KB
testcase_16 AC 22 ms
11,896 KB
testcase_17 AC 19 ms
11,088 KB
testcase_18 AC 5 ms
7,896 KB
testcase_19 AC 344 ms
55,664 KB
testcase_20 AC 349 ms
53,884 KB
testcase_21 AC 107 ms
22,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

VVI edge(214514, VI(0));
vector<bool> f(214514,0);
void dfs(int v, int p) {
	for (auto to:edge[v]) {
		if (to!=p&&!f[to]){
			f[to]=1;
			dfs(to, v);
		}
	}
}

int main(){
	int l, r; cin >> l >> r;
	for(int i=l;i<=r;i++){
		for(int j=i*2;j<=r;j+=i){
			edge[i].push_back(j);
			edge[j].push_back(i);
		}
	}
	int ans=0;
	for(int i=l;i<=r;i++){
		if(!f[i]){
			ans++;
			f[i]=1;
			dfs(i,-1);
		}
	}
	cout << ans-1 << endl;
	return 0;
}
0