/ SeriousOJ /

Record Detail

Compile Error

foo.cc:7:10: fatal error: Ash.cpp: No such file or directory
    7 | #include "Ash.cpp"
      |          ^~~~~~~~~
compilation terminated.

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

#ifndef ONLINE_JUDGE
#include "Ash.cpp"
#else
#define dbg(...)
#define dbgA(...)
#endif

void solve(int cs) {
  int n, x;
  cin >> n >> x;
  
  int mx = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }

  if (x == 1) {
    cout << "1\n";
    return;
  }

  unordered_map<int, int> seen;
  for (auto &it : a) seen[it] += 1;
  pair<int64_t,int> res = {1e13,-1};
  auto check = [&](int k) -> void {
    int cnt = 0;
    int64_t sum = 0;
    for (int i = k; i <= mx; i += k) {
      if (seen[i] > 0) {
        sum += i * seen[i];
      }
    }
    if (res.first > sum) {
      res.first = sum;
      res.second = k;
    }
  };

  for (int i = 1; i <= x; i++) {
    check(i);
  }
  cout << res.second << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-11 10:36:54
Judged At
2024-11-11 03:27:39
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes