結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
6,676 KB
testcase_01 AC 5 ms
6,676 KB
testcase_02 AC 7 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
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() {
  int n, k;
  std::cin >> n >> k;
  std::vector<long long> a(n);
  for (auto& i : a) std::cin >> i;
  auto prime_factor = [](long long x) {
    std::vector<long long> res;
    for (long long i = 2; i * i <= x; ++i) {
      if (x % i == 0) {
        res.push_back(i);
        while (x % i == 0) x /= i;
      }
    }
    if (x != 1) res.push_back(x);
    return res;
  };
  std::set<long long, std::greater<long long>> c;
  for (int i = 0; i < n; i++) {
    c.insert(a[i]);
    auto p = prime_factor(a[i]);
    for (auto j : p) {
      c.insert(j);
    }
  }
  for (int x = 2; x <= 10; x++) {
    c.insert(x);
  }

  for (auto g : c) {
    int cnt = 0;
    for (auto x : a) {
      auto distance = std::min(std::abs(g - x % g), x % g);
      cnt += distance;
    }
    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