結果

問題 No.1059 素敵な集合
ユーザー chocoruskchocorusk
提出日時 2020-05-22 21:49:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 1,459 ms
コンパイル使用メモリ 126,532 KB
最終ジャッジ日時 2025-01-10 14:39:19
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct unionfind{
    int cnt;
    vector<int> par, sz;
    unionfind() {}
    unionfind(int n):par(n), sz(n, 1), cnt(n){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        cnt--;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
    int l, r;
    cin>>l>>r;
    unionfind uf(r-l+1);
    for(int d=l; d<=r; d++){
        for(int i=d; i<=r; i+=d){
            uf.unite(d-l, i-l);
        }
    }
    cout<<uf.cnt-1<<endl;
	return 0;
}
0