結果

問題 No.2609 Decreasing GCDs
ユーザー ripityripity
提出日時 2024-01-19 23:43:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 872 ms / 1,000 ms
コード長 1,614 bytes
コンパイル時間 3,054 ms
コンパイル使用メモリ 211,572 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-19 23:44:20
合計ジャッジ時間 24,109 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 846 ms
6,676 KB
testcase_01 AC 855 ms
6,676 KB
testcase_02 AC 835 ms
6,676 KB
testcase_03 AC 847 ms
6,676 KB
testcase_04 AC 831 ms
6,676 KB
testcase_05 AC 855 ms
6,676 KB
testcase_06 AC 848 ms
6,676 KB
testcase_07 AC 838 ms
6,676 KB
testcase_08 AC 859 ms
6,676 KB
testcase_09 AC 858 ms
6,676 KB
testcase_10 AC 826 ms
6,676 KB
testcase_11 AC 863 ms
6,676 KB
testcase_12 AC 860 ms
6,676 KB
testcase_13 AC 831 ms
6,676 KB
testcase_14 AC 871 ms
6,676 KB
testcase_15 AC 858 ms
6,676 KB
testcase_16 AC 820 ms
6,676 KB
testcase_17 AC 864 ms
6,676 KB
testcase_18 AC 848 ms
6,676 KB
testcase_19 AC 828 ms
6,676 KB
testcase_20 AC 872 ms
6,676 KB
testcase_21 AC 831 ms
6,676 KB
testcase_22 AC 848 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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