結果

問題 No.1059 素敵な集合
ユーザー KensKens
提出日時 2020-05-22 22:23:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,009 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 168,960 KB
実行使用メモリ 5,544 KB
最終ジャッジ日時 2023-09-30 15:30:39
合計ジャッジ時間 2,505 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 14 ms
5,364 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 9 ms
5,128 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
5,472 KB
testcase_19 AC 14 ms
5,344 KB
testcase_20 AC 15 ms
5,544 KB
testcase_21 AC 9 ms
5,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

class Union_Find{
  vector<int> par; vector<int> rank; vector<int> num;
public:
  Union_Find(int n) {
    par = vector<int>(n); rank = vector<int>(n,0); num = vector<int>(n,1);
    rep(i,n) par[i] = i;
  }
  int find(int x) {
    if(par[x] == x) return x;
    else  return par[x] = find(par[x]);
  }
  int number(int x) {
    return num[find(x)];
  }
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x;
    num[x] += num[y];
  } 
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main(){
  ll l, r;
  cin >> l >> r;
  Union_Find uf(r+1);
  for(int i = l; i <= r; i++) {
    for(int j = 1; j*i <= r; j++) uf.unite(i,i*j);
  }
  int ans = -1;
  for(int i = l; i <= r; i++) {
    if(uf.find(i) == i) ans++;
  }
  cout << ans << endl;
  return 0;
}
0