結果

問題 No.1059 素敵な集合
ユーザー scol_kpscol_kp
提出日時 2020-05-22 22:40:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,872 bytes
コンパイル時間 2,558 ms
コンパイル使用メモリ 200,844 KB
最終ジャッジ日時 2025-01-10 14:56:54
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
class UnionFind {
using i64 = std::int64_t;
private:
std::vector<i64> par;
std::vector<i64> sz;
public:
UnionFind(i64 N) : par(N), sz(N, 1) {
for (i64 i = 0; i < N; ++i) par[i] = i;
}
i64 root(i64 x) {
return par[x] == x ? x : par[x] = root(par[x]);
}
bool same(i64 x, i64 y) {
return root(x) == root(y);
}
void unite(i64 x, i64 y) {
x = root(x);
y = root(y);
if (x == y) return;
if (sz[x] < sz[y]) std::swap(x, y);
par[y] = x;
sz[x] += sz[y];
}
i64 size(i64 x) {
return sz[root(x)];
}
void reset(i64 N) {
par.resize(N);
for (i64 i = 0; i < N; ++i) par[i] = i;
sz.assign(N, 1);
}
};
void solve() {
ll L, R;
cin >> L >> R;
UnionFind uf(R - L + 1);
for (ll i = L; i <= R; i++) {
for (ll j = 2 * i; j <= R; j += i) {
uf.unite(i - L, j - L);
}
}
unordered_set<ll> st;
for (ll i = 0; i < R - L + 1; i++) {
st.emplace(uf.root(i));
}
cout << (ll)st.size() - 1 << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
solve();
cout << flush;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0