結果

問題 No.1059 素敵な集合
ユーザー SSRS
提出日時 2020-05-22 21:49:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 173,000 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 09:28:01
合計ジャッジ時間 4,175 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int L, R;
  cin >> L >> R;
  vector<int> g(R + 1, -1);
  int cnt = 0;
  for (int i = L; i <= R; i++){
    if (g[i] == -1){
      g[i] = cnt;
      queue<int> Q;
      Q.push(i);
      while (!Q.empty()){
        int x = Q.front();
        Q.pop();
        for (int j = x * 2; j <= R; j += x){
          if (g[j] == -1){
            g[j] = cnt;
            Q.push(j);
          }
        }
        for (int j = 1; j * j <= x; j++){
          if (x % j == 0){
            if (L <= j && j < x){
              if (g[j] == -1){
                g[j] = cnt;
                Q.push(j);
              }
            }
            int k = x / j;
            if (L <= k && k < x){
              if (g[k] == -1){
                g[k] = cnt;
                Q.push(k);
              }
            }
          }
        }
      }
      cnt++;
    }
  }
  cout << cnt - 1 << endl;
}
0