結果

問題 No.1059 素敵な集合
ユーザー wkwk
提出日時 2020-05-22 22:41:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,310 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 169,440 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 17:47:13
合計ジャッジ時間 2,842 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 205 ms
6,944 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 7 ms
6,940 KB
testcase_19 AC 159 ms
6,944 KB
testcase_20 AC 164 ms
6,940 KB
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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=L; 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]){
                            check[j] = true;
                            que.push(P(j, 0));
                        }
                    }
                }
            }
        }
    }
    cout << ans-1 << endl;
    
    return 0;
}

0