結果

問題 No.2570 最大最大公約数
ユーザー eve__fuyukieve__fuyuki
提出日時 2023-12-08 16:18:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 902 bytes
コンパイル時間 2,225 ms
コンパイル使用メモリ 210,880 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-08 16:18:17
合計ジャッジ時間 3,708 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
6,676 KB
testcase_01 AC 39 ms
6,676 KB
testcase_02 AC 45 ms
6,676 KB
testcase_03 AC 19 ms
6,676 KB
testcase_04 AC 34 ms
6,676 KB
testcase_05 AC 34 ms
6,676 KB
testcase_06 AC 37 ms
6,676 KB
testcase_07 AC 36 ms
6,676 KB
testcase_08 AC 35 ms
6,676 KB
testcase_09 AC 35 ms
6,676 KB
testcase_10 AC 35 ms
6,676 KB
testcase_11 AC 35 ms
6,676 KB
testcase_12 AC 38 ms
6,676 KB
testcase_13 AC 37 ms
6,676 KB
testcase_14 AC 29 ms
6,676 KB
testcase_15 AC 30 ms
6,676 KB
testcase_16 AC 26 ms
6,676 KB
testcase_17 AC 2 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 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    fast_io();
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    vector<long long> divs;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (long long j = 1; j * j <= a[i]; j++) {
            if (a[i] % j == 0) {
                divs.push_back(j);
                if (j * j != a[i]) {
                    divs.push_back(a[i] / j);
                }
            }
        }
    }
    sort(divs.rbegin(), divs.rend());
    divs.erase(unique(divs.begin(), divs.end()), divs.end());
    for (long long d : divs) {
        long long need = 0;
        for (int i = 0; i < n; i++) {
            need += min(a[i] % d, d - a[i] % d);
        }
        if (need <= k) {
            cout << d << endl;
            return 0;
        }
    }
}
0