結果
問題 | No.1059 素敵な集合 |
ユーザー |
![]() |
提出日時 | 2020-06-08 18:47:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,231 bytes |
コンパイル時間 | 2,179 ms |
コンパイル使用メモリ | 195,512 KB |
最終ジャッジ日時 | 2025-01-11 00:12:51 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using namespace std; using ll = long long; using ld = long double; template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; } struct UnionFind { vector<int> data; UnionFind(int n) : data(n, -1) {} int root(int x) { if(data[x] < 0) return x; return data[x] = root(data[x]); } bool unite(int x, int y) { x = root(x), y = root(y); if(x == y) return false; if(data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return true; } int same(int x, int y) { return root(x) == root(y); } int size(int x) { return -data[root(x)]; } }; int l, r; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> l >> r; UnionFind uf(r-l+1); REP(i, l, r+1) { if(uf.root(i-l) != i-l) continue; for(ll j = i*2; j <= r; j += i) { uf.unite(i-l, j-l); } } ll ans = 0; rep(i, r-l+1) if(uf.root(i) == i) ans++; ans--; cout << ans << '\n'; return 0; }