結果

問題 No.2570 最大最大公約数
ユーザー momoyuu
提出日時 2023-12-15 15:11:07
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 97,224 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-13 17:17:25
合計ジャッジ時間 3,138 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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