結果
問題 | No.2570 最大最大公約数 |
ユーザー |
![]() |
提出日時 | 2023-12-06 01:38:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 348 ms / 2,000 ms |
コード長 | 728 bytes |
コンパイル時間 | 5,299 ms |
コンパイル使用メモリ | 253,908 KB |
最終ジャッジ日時 | 2025-02-18 08:12:32 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#include <stdio.h>#include <atcoder/all>#include <bits/stdc++.h>using namespace std;using namespace atcoder;using mint = modint998244353;#define rep(i,n) for (int i = 0; i < (n); ++i)#define Inf32 1000000001#define Inf64 2000000000000000001int main(){int N,K;cin>>N>>K;vector<long long> a(N);rep(i,N)cin>>a[i];vector<long long> y;rep(i,N){for(long long j=1;j*j<=a[i];j++){if(a[i]%j==0){y.push_back(j);y.push_back(a[i]/j);}}}sort(y.begin(),y.end());y.erase(unique(y.begin(),y.end()),y.end());long long ans = 1;rep(i,y.size()){long long sum = 0;rep(j,N){sum += min(a[j]%y[i],y[i] - (a[j]%y[i]));}if(sum<=K)ans = y[i];}cout<<ans<<endl;return 0;}