結果

問題 No.1059 素敵な集合
ユーザー wk
提出日時 2020-05-22 22:41:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,310 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 172,016 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-05 19:09:30
合計ジャッジ時間 2,881 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 5 WA * 14
権限があれば一括ダウンロードができます

ソースコード

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