結果
問題 | No.1059 素敵な集合 |
ユーザー |
![]() |
提出日時 | 2020-05-22 22:27:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 1,405 bytes |
コンパイル時間 | 1,302 ms |
コンパイル使用メモリ | 123,172 KB |
最終ジャッジ日時 | 2025-01-10 14:52:34 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <iostream>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <string.h>#include <map>#include <numeric>#include <random>#include <queue>#include <deque>#include <tuple>#include <iomanip>#include <iterator>#include <functional>using namespace std;typedef long long ll;const int INF = (1 << 30) - 1;const ll INFLL= (1LL << 61) - 1;const int MOD = 1000000007;#define ALL(a) (a).begin(),(a).end()#define rALL(a) (a).rbegin(),(a).rend()#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)struct UnionFind {vector<int> par;UnionFind(int n) : par(n, -1) { }void init(int n) { par.assign(n, -1); }int root(int x) {if (par[x] < 0) return x;else return par[x] = root(par[x]);}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 (par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};int main(){cin.tie(nullptr);ios::sync_with_stdio(false);ll L,R;cin>>L>>R;vector<bool>ok(R+1, false);UnionFind uf(R+1);for(ll i=L; i<=R; i++){for(ll j=2; i*j<=R; j++){uf.merge(i,i*j);}}int ans=0;FOR(i,L,R+1){if(i==uf.root(i)){ans++;}}cout<<ans-1<<endl;}