結果

問題 No.2570 最大最大公約数
ユーザー momoyuumomoyuu
提出日時 2023-12-15 15:11:07
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 97,124 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-15 15:11:12
合計ジャッジ時間 2,863 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
6,548 KB
testcase_01 AC 43 ms
6,548 KB
testcase_02 AC 49 ms
6,548 KB
testcase_03 AC 21 ms
6,548 KB
testcase_04 AC 41 ms
6,548 KB
testcase_05 AC 35 ms
6,548 KB
testcase_06 AC 38 ms
6,548 KB
testcase_07 AC 39 ms
6,548 KB
testcase_08 AC 37 ms
6,548 KB
testcase_09 AC 37 ms
6,548 KB
testcase_10 AC 36 ms
6,548 KB
testcase_11 AC 37 ms
6,548 KB
testcase_12 AC 40 ms
6,548 KB
testcase_13 AC 39 ms
6,548 KB
testcase_14 AC 30 ms
6,548 KB
testcase_15 AC 31 ms
6,548 KB
testcase_16 AC 27 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 3 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 1 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    vector<ll> use;
    for(int i = 0;i<n;i++){
        for(ll j = 1;j*j<=a[i];j++){
            if(a[i]%j!=0) continue;
            use.push_back(j);
            use.push_back(a[i]/j);
        }
    }
    ll ans = 0;
    for(int i = 0;i<use.size();i++){
        ll now = use[i];
        ll need = 0;
        for(int j = 0;j<n;j++){
            ll nk = a[j] / now;
            ll cnt = a[j] - nk * now;
            nk++;
            cnt = min(cnt,nk*now-a[j]);
            need += cnt;
        }
        if(need<=k) ans = max(ans,now);
    }
    cout<<ans<<endl;

}
0