結果

問題 No.2609 Decreasing GCDs
ユーザー ripity
提出日時 2024-01-19 23:43:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 816 ms / 1,000 ms
コード長 1,614 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 203,516 KB
最終ジャッジ日時 2025-02-18 21:36:58
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    vector<int> V = {2, 3, 5, 7, 11, 13, 17};
    vector<int> P;
    for( int i = 0; i < 1<<V.size(); i++ ) {
        int prod = 1;
        for( int j = 0; j < V.size(); j++ ) {
            if((i>>j)&1) prod *= V[j];
        }
        P.push_back(prod);
    }
    sort(P.rbegin(), P.rend());
    int V_PROD = P.front();
    vector<long long> A;
    for( int prod : P ) {
        long long c = 1;
        if(!A.empty()) {
            c = 1;
            for(;;c++) {
                bool divisible = false;
                for( int v : V ) divisible = divisible || c%v == 0;
                if(!divisible&&prod*c>A.back()) break;
            }
        }
        int n = A.size();
        if(A.size()<=1||gcd(A[n-2], A[n-1])>gcd(A[n-1], prod*c)) A.push_back(prod*c);
    }
    int N;
    cin >> N;
    // for( int i = 0; i < N-1; i++ ) {
    //     cerr << gcd(A[i], A[i+1]) << (i==N-2?"\n":" ");
    // }
    for( int i = 0; i < N; i++ ) {
        cout << A[i] << (i==N-1?"\n":" ");
    }
}

/*

[2, 3, 5, 7, 11]

2, 3, 5, 7
2, 3, 5, 7 | 11

2, 3, 5, 7 | 13
*, 3, 5, 7 | 29

2, 3, 5, 7 | 17
2, *, 5, 7, 11

2, 3, 5, 7, 11
*, *, 5, 7, 11

2, 3, 5, 7, 11
2, 3, 5, *, 11

2, 3, 5, 7, 11
*, 3, *, 7, 11

2, 3, 5, 7, 11
*, 3, 5, *, 11

2, 3, 5, 7, 11
2, *, *, 7, 11

2, 3, 5, 7, 11
2, *, 5, *, 11

2, 3, 5, 7, 11
*, *, *, 7, 11

2, 3, 5, 7, 11
2, 3, *, *, 11

2, 3, 5, 7, 11
*, *, 5, *, 11

2, 3, 5, 7, 11
*, 3, *, *, 11

2 : 1
3 : 2
5 : 3
6 : 1 2
7 : 4
10 : 1 3
14 : 1 4
15 : 2 3
21 : 2 4
30 : 1 2 3
35 : 3 4
42 : 1 2 4
70 : 1 3 4
105 : 2 3 4
210 : 1 2 3 4

*/
0