結果

問題 No.2570 最大最大公約数
ユーザー 👑 OnjoujiTokiOnjoujiToki
提出日時 2023-12-06 02:13:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,781 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 139,372 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-06 02:14:00
合計ジャッジ時間 3,727 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
6,676 KB
testcase_01 AC 40 ms
6,676 KB
testcase_02 AC 46 ms
6,676 KB
testcase_03 AC 19 ms
6,676 KB
testcase_04 AC 35 ms
6,676 KB
testcase_05 AC 34 ms
6,676 KB
testcase_06 AC 37 ms
6,676 KB
testcase_07 AC 37 ms
6,676 KB
testcase_08 AC 36 ms
6,676 KB
testcase_09 AC 35 ms
6,676 KB
testcase_10 AC 36 ms
6,676 KB
testcase_11 AC 35 ms
6,676 KB
testcase_12 AC 40 ms
6,676 KB
testcase_13 AC 38 ms
6,676 KB
testcase_14 AC 30 ms
6,676 KB
testcase_15 AC 31 ms
6,676 KB
testcase_16 AC 27 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 <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

void solve() {
  long long n, k;
  std::cin >> n >> k;
  std::vector<long long> a(n);
  for (auto& i : a) std::cin >> i;
  auto get_divisors = [](long long n) {
    std::vector<long long> res;
    for (long long i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        res.push_back(i);
        if (i * i != n) res.push_back(n / i);
      }
    }
    return res;
  };
  std::set<long long, std::greater<long long>> c;
  for (int i = 0; i < n; i++) {
    auto p = get_divisors(a[i]);
    for (auto j : p) {
      c.insert(j);
    }
  }

  for (auto g : c) {
    long long cnt = 0;
    for (auto x : a) {
      long long distance = std::abs(g * (x / g + 1) - x);
      if (x > g) distance = std::min(distance, x % g);
      if (x == distance) distance = 0;
      cnt += distance;
      // if (g == 998244353) std::cout << distance << '\n';
    }

    if (cnt <= k) {
      std::cout << g << '\n';
      return;
    }
  }
  std::cout << 1 << '\n';
}
int main() {
  int t = 1;
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  // std::cin >> t;
  while (t--) solve();

  return 0;
}
0