結果

問題 No.1059 素敵な集合
ユーザー wkwk
提出日時 2020-05-22 23:06:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 1,344 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 170,604 KB
実行使用メモリ 5,020 KB
最終ジャッジ日時 2023-09-30 15:32:34
合計ジャッジ時間 3,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 205 ms
5,020 KB
testcase_02 AC 40 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 25 ms
4,380 KB
testcase_07 AC 23 ms
4,380 KB
testcase_08 AC 40 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 48 ms
4,376 KB
testcase_11 AC 26 ms
4,380 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 69 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 138 ms
4,380 KB
testcase_16 AC 33 ms
4,380 KB
testcase_17 AC 34 ms
4,376 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 158 ms
4,484 KB
testcase_20 AC 164 ms
4,380 KB
testcase_21 AC 147 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
using namespace std;

bool check[200005];
int L, R;

typedef pair<int, int> P;

int main()
{   
    cin >> L >> R;
    REP(i, R+1) check[i] = false;
    int ans = 0;
    for(int i=L;i<=R;i++){
        if(check[i]) continue;
        ans++;
        queue<P> que;
        que.push(P(i, 0));
        check[i] = true;
        while(!que.empty()){
            P p = que.front(); que.pop();
            
            if(p.second == 0){
                for(int j=2; p.first * j <= R; j++){
                    if(!check[p.first*j]){
                        check[p.first*j] = true;
                        que.push(P(p.first * j, 1));
                    }
                }
            }else{
                for(int j=2; j*j <= p.first; j++){
                    if(p.first%j==0){
                        if(!check[p.first/j] && p.first/j>=L){
                            check[p.first/j] = true;
                            que.push(P(p.first/j, 0));
                        }
                        if(!check[j] && j>=L){
                            check[j] = true;
                            que.push(P(j, 0));
                        }
                    }
                }
            }
            
        }
    }
    cout << ans-1 << endl;
    
    return 0;
}

0