結果

問題 No.1059 素敵な集合
ユーザー chocopuuchocopuu
提出日時 2020-05-22 21:43:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 694 ms / 2,000 ms
コード長 1,641 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 210,984 KB
実行使用メモリ 14,196 KB
最終ジャッジ日時 2023-09-30 15:26:27
合計ジャッジ時間 7,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 5 ms
7,704 KB
testcase_02 AC 179 ms
6,004 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 103 ms
4,956 KB
testcase_07 AC 96 ms
4,968 KB
testcase_08 AC 171 ms
5,700 KB
testcase_09 AC 28 ms
4,380 KB
testcase_10 AC 185 ms
5,348 KB
testcase_11 AC 107 ms
4,804 KB
testcase_12 AC 58 ms
4,504 KB
testcase_13 AC 285 ms
6,404 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 572 ms
8,388 KB
testcase_16 AC 138 ms
5,544 KB
testcase_17 AC 151 ms
5,608 KB
testcase_18 AC 455 ms
14,196 KB
testcase_19 AC 694 ms
8,480 KB
testcase_20 AC 694 ms
8,236 KB
testcase_21 AC 629 ms
9,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#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 FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

struct UF{
	vector<int>par,sz;
	void init(int n){
		par.resize(n);
		sz.resize(n);
		for(int i=0;i<n;i++){
			par[i]=i;
			sz[i]=1;
		}
	}
	int find(int x){
		return x==par[x]?x:par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		sz[x]+=sz[y];
		par[y]=x;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};

void solve(){
	int L,R;
	cin >> L >> R;
	vector<int>v(R + 1);
	UF uf;
	uf.init(R + 1);
	if(L == 1){
		out(0);
		return;
	}
	int ans = 0;
	RFOR(i,L,R + 1){
		int zero = 0;
		for(int j = 2;j * j <= i;j++){
			if(i % j)continue;
			if(IN(L,j,R + 1))uf.unite(i,j);
			if(IN(L,i / j,R + 1))uf.unite(i,i / j);
		}
	}
	map<int,int>mp;
	FOR(i,L,R + 1)mp[uf.find(i)]++;
	out(mp.size() - 1);
}

signed main(){
	IOS();
	int Q = 1;
	//cin >> Q;
	while(Q--)solve();
}
0