結果

問題 No.1059 素敵な集合
ユーザー monnumonnu
提出日時 2021-04-16 23:26:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 167,864 KB
実行使用メモリ 6,700 KB
最終ジャッジ日時 2023-09-16 03:03:12
合計ジャッジ時間 2,619 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,596 KB
testcase_01 AC 14 ms
6,700 KB
testcase_02 AC 5 ms
4,660 KB
testcase_03 AC 3 ms
4,700 KB
testcase_04 AC 3 ms
4,540 KB
testcase_05 AC 3 ms
4,548 KB
testcase_06 AC 4 ms
4,716 KB
testcase_07 AC 5 ms
4,544 KB
testcase_08 AC 5 ms
4,544 KB
testcase_09 AC 3 ms
4,704 KB
testcase_10 AC 7 ms
4,708 KB
testcase_11 AC 5 ms
4,720 KB
testcase_12 AC 4 ms
4,656 KB
testcase_13 AC 8 ms
4,544 KB
testcase_14 AC 2 ms
4,636 KB
testcase_15 AC 12 ms
4,588 KB
testcase_16 AC 5 ms
4,544 KB
testcase_17 AC 5 ms
4,596 KB
testcase_18 AC 3 ms
4,704 KB
testcase_19 AC 21 ms
5,680 KB
testcase_20 AC 21 ms
5,512 KB
testcase_21 AC 11 ms
4,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0