結果

問題 No.2609 Decreasing GCDs
ユーザー t98slidert98slider
提出日時 2024-01-21 12:33:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,143 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 210,368 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-21 12:33:52
合計ジャッジ時間 3,307 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> ans(n, 1);
    vector<bool> tb(251, true);
    tb[0] = tb[1] = false;
    vector<int> p;
    for(int i = 2; i <= 250; i++){
        if(!tb[i]) continue;
        p.push_back(i);
        p.push_back(i * i);
        if(i < 10){
            p.push_back(i * i * i);
            p.push_back(i * i * i * i);
            p.push_back(i * i * i * i * i);
        }
        for(int j = 2 * i; j <= 250; j += i) tb[j] = false;
    }
    sort(p.begin(), p.end());
    for(int i = 0; i + 2 < n; i++){
        ans[n - 2 - i] = lcm(ans[n - 2 - i], p[i + 1]);
        ans[n - 3 - i] = lcm(ans[n - 3 - i], p[i + 1]);
    }
    for(int i = 0; i < n; i++){
        if(i >= 1 && ans[i - 1] >= ans[i]){
            int d = ans[i - 1] / ans[i] + 1;
            while(gcd(d, ans[i - 1]) != 1 || (i + 1 < n && gcd(d, ans[i + 1]) != 1)) d++;
            ans[i] *= d;
        }
        //if(i >= 1) cerr << gcd(ans[i - 1], ans[i]) << " ";
        cout << ans[i] << (i + 1 == n ? '\n' : ' ');
    }
}
0