結果

問題 No.1059 素敵な集合
ユーザー SSRSSSRS
提出日時 2020-05-22 21:49:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 169,844 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-30 15:27:34
合計ジャッジ時間 4,467 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 251 ms
4,560 KB
testcase_02 AC 67 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 39 ms
4,380 KB
testcase_07 AC 37 ms
4,376 KB
testcase_08 AC 64 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 67 ms
4,380 KB
testcase_11 AC 41 ms
4,380 KB
testcase_12 AC 23 ms
4,380 KB
testcase_13 AC 105 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 206 ms
4,380 KB
testcase_16 AC 53 ms
4,376 KB
testcase_17 AC 57 ms
4,376 KB
testcase_18 AC 163 ms
4,380 KB
testcase_19 AC 249 ms
4,428 KB
testcase_20 AC 249 ms
4,568 KB
testcase_21 AC 226 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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