結果
問題 |
No.1059 素敵な集合
|
ユーザー |
![]() |
提出日時 | 2021-04-16 23:26:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 771 bytes |
コンパイル時間 | 1,579 ms |
コンパイル使用メモリ | 170,292 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-03 04:21:16 |
合計ジャッジ時間 | 2,492 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll=long long; using Graph=vector<vector<int>>; #define MAX 200003 #define MOD 998244353 #define INF 1000000000 vector<int> parent(200001); int find(int x){ int y=parent[x]; while(y!=parent[y]){ y=find(y); } return parent[x]=y; } void unite(int a,int b){ int x=find(a); int y=find(b); if(x!=y){ parent[x]=y; } } int main(){ int L,R; cin>>L>>R; for(int i=0;i<=200000;i++){ parent[i]=i; } for(int i=L;i<R;i++){ for(int j=2;i*j<=R;j++){ unite(i,i*j); } } vector<int> cnt(200001,0); for(int i=L;i<=R;i++){ cnt[find(i)]=1; } int ans=-1; for(int i=L;i<=R;i++){ ans+=cnt[i]; } cout<<ans<<endl; }