結果

問題 No.1059 素敵な集合
ユーザー yurujirouyurujirou
提出日時 2021-09-22 19:53:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,569 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 81,524 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2023-09-18 19:41:53
合計ジャッジ時間 2,660 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 21 ms
5,188 KB
testcase_02 AC 12 ms
4,764 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 12 ms
4,560 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 11 ms
4,432 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 16 ms
5,048 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 25 ms
5,656 KB
testcase_16 AC 10 ms
4,392 KB
testcase_17 AC 11 ms
4,848 KB
testcase_18 AC 25 ms
8,832 KB
testcase_19 AC 22 ms
5,372 KB
testcase_20 AC 23 ms
5,652 KB
testcase_21 AC 29 ms
6,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
using namespace std;

//#include <atcoder/all>
//using namespace atcoder;

#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define RREP(i,n) for(int i = (int)n-1; i >= 0; i--)
#define LREP(i,n) for(LL i = 0; i < (LL)n; i++)

#define Vi vector<int>
#define Vl vector<long long>
#define LP pair<long long ,long long>
#define P pair<int, int>
#define T3 tuple<LL, LL, LL>
#define T4 tuple<LL, LL, LL, LL>
#define INF 1000000007
#define SIZE	300010
#define MOD 1000000007
typedef long long LL;

int L, R;

int parent[SIZE], s[SIZE];
void init() {
	for (int i = L; i <= R; i++) {
		parent[i] = i;
		s[i] = 1;
	}
}

int par(int a) {
	if (parent[a] == a) return a;
	else return parent[a] = par(parent[a]);
}

int size(int a) {
	int pa = par(a);
	return s[pa];
}

void merge(int a, int b) {
	int pa = par(a), pb = par(b);
	if (pa != pb) {
		if (size(pa) > size(pb)) swap(pa, pb);
		parent[pa] = pb;
		s[pb] += s[pa];
	}
}

bool same(int a, int b) {
	int pa = par(a), pb = par(b);
	if (pa == pb) return true;
	else return false;
}

int main() {
	cin >> L >> R;

	init();
	for (int i = L; i <= R; i++) {
		for (int j = i; j <= R; j += i) {
			merge(i, j);
		}
	}
	set<int> S;
	for (int i = L; i <= R; i++) {
		S.insert(par(i));
	}
	cout << S.size() - 1 << endl;
}
0