結果
| 問題 | No.1059 素敵な集合 |
| コンテスト | |
| ユーザー |
rokahikou1
|
| 提出日時 | 2020-05-27 20:49:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 2,229 bytes |
| コンパイル時間 | 933 ms |
| コンパイル使用メモリ | 104,492 KB |
| 実行使用メモリ | 9,472 KB |
| 最終ジャッジ日時 | 2024-07-23 09:39:09 |
| 合計ジャッジ時間 | 1,844 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
vector<bool> sieve(int x) { // range...[0,x]
vector<bool> flags(x + 1, true);
flags[0] = false, flags[1] = false;
for(int i = 2; i * i <= x; i++) {
if(!flags[i])
continue;
for(int mult = i * i; mult < x; mult += i)
flags[mult] = false;
}
return flags;
}
ll getLdiv(ll n) {
for(ll i = 2; i * i <= n; i++) {
if(n % i == 0) {
return n / i;
}
}
return 1;
}
// UnionFind
struct UnionFind {
vector<ll> par;
vector<ll> siz;
UnionFind(ll N) : par(N), siz(N, 1LL) {
for(int i = 0; i < N; i++)
par[i] = i;
}
int root(int x) {
if(par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if(rx == ry)
return;
if(siz[rx] < siz[ry])
swap(rx, ry);
siz[rx] += siz[ry];
par[ry] = rx;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
ll size(ll x) { return siz[root(x)]; }
};
int main() {
int L, R;
cin >> L >> R;
vector<bool> A(200001, 1);
vector<bool> is_prime = sieve(200001);
if(L == 1) {
cout << 0 << endl;
return 0;
}
UnionFind uf(R - L + 1);
for(int i = L; i <= R; i++) {
for(int j = i * 2; j <= R; j += i) {
uf.unite(i - L, j - L);
}
}
set<int> se;
for(int i = L; i <= R; i++) {
se.insert(uf.root(i - L));
}
cout << se.size() - 1 << endl;
return 0;
}
rokahikou1