結果
問題 | No.1059 素敵な集合 |
ユーザー | i_mrhj |
提出日時 | 2020-05-22 22:57:12 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 1,581 bytes |
コンパイル時間 | 862 ms |
コンパイル使用メモリ | 97,384 KB |
実行使用メモリ | 9,204 KB |
最終ジャッジ日時 | 2023-09-30 15:32:17 |
合計ジャッジ時間 | 1,815 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 4 ms
4,932 KB |
testcase_02 | AC | 7 ms
5,188 KB |
testcase_03 | AC | 2 ms
4,412 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 5 ms
4,756 KB |
testcase_07 | AC | 5 ms
4,672 KB |
testcase_08 | AC | 6 ms
4,980 KB |
testcase_09 | AC | 4 ms
4,468 KB |
testcase_10 | AC | 6 ms
4,836 KB |
testcase_11 | AC | 5 ms
4,664 KB |
testcase_12 | AC | 4 ms
4,748 KB |
testcase_13 | AC | 8 ms
5,492 KB |
testcase_14 | AC | 3 ms
4,460 KB |
testcase_15 | AC | 11 ms
5,732 KB |
testcase_16 | AC | 6 ms
5,052 KB |
testcase_17 | AC | 6 ms
5,160 KB |
testcase_18 | AC | 28 ms
9,204 KB |
testcase_19 | AC | 8 ms
5,320 KB |
testcase_20 | AC | 9 ms
5,372 KB |
testcase_21 | AC | 12 ms
6,172 KB |
ソースコード
#include <cstdio> #include <climits> #include <cmath> #include <iostream> #include <iomanip> #include <string> #include <cstdio> #include <climits> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <utility> #include <queue> #include <cstring> #include <set> #include <map> #include <complex> #include <tuple> #define rep(i, n) for (int i = 0; i < int(n); i++) using namespace std; long long MOD = 1000000007; long long INF = 1000000000000000000; //10^18 typedef long long ll; typedef unsigned long long ull; ll powMod(ll x, ll n, ll mod) { if (n == 0) return 1; ll t = powMod(x, n/2, mod); t = t * t % mod; if (n & 1) return t * x % mod; return t; } ll gcd(ll a, ll b) { if (a == 0 || b == 0) return a + b; if (b > a) return gcd(b, a); return gcd(b, a % b); } int get_parent(int i, int *parent) { while (i != parent[i]) i = parent[i]; return i; } void Union(int i, int j, int *parent, int *rank) { i = get_parent(i, parent); j = get_parent(j, parent); if (i == j) return; if (rank[i] < rank[j]) swap(i, j); parent[j] = i; rank[i] = max(rank[i], rank[j] + 1); return; } int main(void) { int l, r; cin >> l >> r; int parent[200200], rank[200200] = {}; for (int i = l; i <= r; i++) parent[i] = i; for (int i = l; i <= r; i++) { if (get_parent(i, parent) == i) { for (int j = 2; i*j <= r; j++) { Union(i, i*j, parent, rank); } } } set<int> s; for (int i = l; i <= r; i++) { if (get_parent(i, parent) == i) s.insert(i); } cout << s.size() - 1 << endl; }