結果

問題 No.2609 Decreasing GCDs
ユーザー InTheBloomInTheBloom
提出日時 2024-01-19 22:14:01
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 1,000 ms
コード長 1,219 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 99,644 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-19 22:14:04
合計ジャッジ時間 2,323 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> enumPrimes (int begin, int end) {
    vector<int> res;
    if (end <= 1) return res;

    vector<bool> isPrime(end+1, true);
    isPrime[0] = isPrime[1] = false;

    for (int i = 0; i <= end; i++) {
        if (!isPrime[i]) continue;
        int j = i;
        while (1LL*i*j <= end) {
            isPrime[i*j] = false;
            j++;
        }
    }

    for (int i = begin; i <= end; i++) if (isPrime[i]) res.push_back(i);
    return res;
}

int main () {
    vector<int> p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
    reverse(p.begin(), p.end());

    vector<int> ans(25);
    for (int i = 0; i < ans.size(); i++) ans[i] = p[i]*p[i+1];

    auto primes = enumPrimes(103, 1000000);
    int cur = 0;

    for (int i = 1; i < ans.size(); i++) {
        while (true) {
            if (ans[i-1] < primes[cur] * ans[i]) {
                ans[i] *= primes[cur];
                break;
            }
            cur++;
        }
    }

    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        cout << ans[i] << (i==N-1 ? '\n' : ' ');
    }

    return 0;
}
0