結果

問題 No.2081 Make a Test Case of GCD Subset
ユーザー t98slidert98slider
提出日時 2022-09-26 07:32:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,562 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 174,916 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 02:44:07
合計ジャッジ時間 6,647 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int mx = 100000;
    vector<bool> tb(mx + 1, true);
    vector<int> p;
    for(int i = 2; i <= mx; i++){
        if(!tb[i])continue;
        p.push_back(i);
        for(int j = 2 * i; j <= mx; j += i){
            tb[j] = false;
        }
    }
    int N;
    cin >> N;
    if(N == 0)N += 998244353;
    vector<bool> used(p.size(), false);
    vector<vector<int>> tb2(30);
    int cnt = 29;
    for(int i = 0; i < p.size() && cnt >= 0; i++){
        if(used[i])continue;
        ll v = p[i];
        used[i] = true;
        tb2[cnt].push_back(v);
        if(cnt == 0)break;
        while(tb2[cnt].size() < cnt && tb2[cnt].back() * v <= mx){
            tb2[cnt].push_back(tb2[cnt].back() * v);
        }
        for(int j = p.size() - 1; j >= 0 && tb2[cnt].size() < cnt; j--){
            if(used[j])continue;
            if(v * p[j] > mx)continue;
            used[j] = true;
            tb2[cnt].push_back(v * p[j]);
        }
        for(int j = p.size() - 1; j >= 0; j--){
            if(used[j])continue;
            used[j] = true;
            tb2[cnt].push_back(p[j]);
            break;
        }
        cnt--;
    }
    vector<int> ans;
    for(int i = 29; i >= 0; i--){
        if(N >> i & 1){
            ans.insert(ans.end(), tb2[i].begin(), tb2[i].end());
        }
    }
    cout << ans.size() << '\n';
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << (i + 1 == ans.size() ? '\n' : ' ');
    }
}
0