/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 12ms 1.066 MiB
#3 Accepted 13ms 1.309 MiB
#4 Accepted 12ms 1.062 MiB
#5 Accepted 13ms 1.066 MiB
#6 Accepted 15ms 1.312 MiB
#7 Accepted 19ms 1.066 MiB
#8 Accepted 39ms 1.312 MiB
#9 Accepted 124ms 1.387 MiB
#10 Accepted 289ms 2.066 MiB
#11 Accepted 505ms 3.605 MiB
#12 Accepted 469ms 3.527 MiB
#13 Accepted 465ms 3.742 MiB
#14 Accepted 464ms 3.746 MiB
#15 Accepted 473ms 3.648 MiB
#16 Accepted 481ms 3.684 MiB
#17 Accepted 501ms 1.965 MiB
#18 Accepted 499ms 1.078 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mx = 1e6+9;

int val[mx];

int32_t main () {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;
  cin >> t;
  while (t--) {
      int n, x, ans = INT_MAX, tot = INT_MAX;
      cin >> n >> x;
      int a[n];
      map<int,int>m;
      vector<int>v;
      for (int i = 0; i < n; i++) {
          cin >> a[i];
      }
      for (int i = 0; i < n; i++) {
          for (int j = 1; j*j <= a[i]; j++) {
              if (a[i]%j == 0) {
                  val[j] += a[i];
                  if (!m[j]) v.push_back(j);
                  if (j != a[i]/j) {
                      val[a[i]/j] += a[i];
                      if (!m[a[i]/j]) v.push_back(a[i]/j);
                  }
                  m[j] = m[a[i]/j] = 1;
              }
          }
      }
      sort (v.begin(), v.end());
          for (int i = 0; i < v.size(); i++) {
              if (val[v[i]] < tot && v[i] <= x) {
                  ans = v[i];
                  tot = val[v[i]];
              }
              if (val[v[i]+1] < tot && v[i]+1 <= x) {
                  ans = v[i]+1;
                  tot = val[v[i]+1];
              }
          }
      cout << ans << "\n";
      for (int i = 0; i < n; i++) {
          for (int j = 1; j*j <= a[i]; j++) {
              if (a[i]%j == 0) {
                  val[j] = val[a[i]/j] = 0;
              }
          }
      }
  }
}

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 16:52:40
Judged At
2024-11-11 03:32:41
Judged By
Score
100
Total Time
505ms
Peak Memory
3.746 MiB