結果
問題 |
No.1059 素敵な集合
|
ユーザー |
![]() |
提出日時 | 2020-05-23 00:10:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 1,522 bytes |
コンパイル時間 | 1,661 ms |
コンパイル使用メモリ | 175,332 KB |
実行使用メモリ | 9,472 KB |
最終ジャッジ日時 | 2024-07-23 09:35:34 |
合計ジャッジ時間 | 2,627 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using vin=vector<int>; using vll=vector<long long>; using vvin=vector<vector<int>>; using vvll=vector<vector<long long>>; using vstr=vector<string>; using vvstr=vector<vector<string>>; using vch=vector<char>; using vvch=vector<vector<char>>; using vbo=vector<bool>; using vvbo=vector<vector<bool>>; using vpii=vector<pair<int,int>>; using pqsin=priority_queue<int,vector<int>,greater<int>>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<<fixed<<setprecision((int)n) const int inf=1e9+7; const ll INF=1e18; vin par(200050); vin deep(200050); void init(int n); int root(int x); void unite(int x,int y); bool same(int x,int y); int main(){ int l,r;cin>>l>>r; if(l==1){ cout<<0<<endl; return 0; } init(r-l+1); rep2(i,l,r+1)for(int j=2*i;j<r+1;j+=i){ if(!same(i-l,j-l))unite(i-l,j-l); } set<int> tmp; int ans=0; rep(i,r-l+1)tmp.insert(root(i)); cout<<tmp.size()-1<<endl; } void init(int n){ rep(i,n){ par[i]=i; deep[i]=0; } } int root(int x){ if(par[x]==x)return x; else return par[x]=root(par[x]); } void unite(int x,int y){ x=root(x); y=root(y); if(x==y)return; if(deep[x]<deep[y])par[x]=y; else{ par[y]=x; if(deep[x]==deep[y])deep[x]++; } } bool same(int x,int y){ return root(x)==root(y); }