結果
| 問題 | No.1059 素敵な集合 |
| コンテスト | |
| ユーザー |
kyort0n
|
| 提出日時 | 2020-05-22 21:33:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 2,000 ms |
| コード長 | 1,693 bytes |
| コンパイル時間 | 1,706 ms |
| コンパイル使用メモリ | 172,540 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-23 09:25:07 |
| 合計ジャッジ時間 | 2,503 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long long INF = 1e18;
//const ll mod = 1000000007;
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) {
init(n);
}
void init(int n = 1) {
par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
}
else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (rank[x] < rank[y]) swap(x, y);
if (rank[x] == rank[y]) ++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x){
return Size[root(x)];
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll L, R;
cin >> L >> R;
UnionFind uni(R + 1);
for(ll i = L; i <= R; i++) {
for(ll j = 2 * i; j <= R; j += i) {
uni.merge(i, j);
}
}
ll ans = -1;
for(ll i = L; i <= R; i++) {
if(uni.root(i) == i) ans++;
}
cout << ans << endl;
return 0;
}
kyort0n