結果

問題 No.1059 素敵な集合
ユーザー leaf_1415leaf_1415
提出日時 2020-05-22 21:56:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,461 bytes
コンパイル時間 886 ms
コンパイル使用メモリ 82,648 KB
実行使用メモリ 8,488 KB
最終ジャッジ日時 2023-09-30 15:28:32
合計ジャッジ時間 2,295 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 20 ms
7,060 KB
testcase_02 AC 16 ms
4,676 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 11 ms
4,380 KB
testcase_08 AC 16 ms
4,424 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 15 ms
4,380 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 21 ms
4,560 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 32 ms
4,864 KB
testcase_16 AC 14 ms
4,380 KB
testcase_17 AC 14 ms
4,500 KB
testcase_18 AC 27 ms
8,488 KB
testcase_19 AC 26 ms
5,620 KB
testcase_20 AC 26 ms
5,428 KB
testcase_21 AC 34 ms
5,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};


llint l, r;
UnionFind uf(200005);
set<llint> S;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> l >> r;
	
	for(int i = 1; i <= 200000; i++){
		for(int j = i*2; j <= 200000; j+=i){
			if(i >= l && i <= r && j >= l && j <= r) uf.unite(i, j);
		}
	}
	
	for(int i = l; i <= r; i++) S.insert(uf.root(i));
	cout << (llint)S.size()-1 << endl;
	
	return 0;
}
0