/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 533ms 89.703 MiB
#2 Accepted 545ms 90.012 MiB
#3 Accepted 545ms 90.328 MiB
#4 Accepted 546ms 90.141 MiB
#5 Accepted 547ms 90.102 MiB
#6 Accepted 552ms 90.109 MiB

Code

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

template<class Fun> class y_combinator_result {
  Fun fun_;
public:
  template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
  template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) { os << '('; apply([&os](const Args&... args) { size_t n = 0; ((os << args << (++n != sizeof...(Args) ? ", " : "")), ...); }, t); return os << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

template<typename T>ostream& operator<<(ostream& os, queue<T>& _q) { queue<T> q = _q; os << '{'; string sep; while (!q.empty()) { os << sep << q.front(); sep = ", "; q.pop(); } return os << '}';}
template<typename T>ostream& operator<<(ostream& os, stack<T> st) { os << '{'; string sep; while (!st.empty()) { os << sep << st.top(); sep = ", "; st.pop(); } return os << '}';}
template<typename T, typename Container, typename Compare>ostream& operator<<(ostream& os, priority_queue<T, Container, Compare> pq) { os << '{'; string sep; while (!pq.empty()) { os << sep << pq.top(); sep = ", "; pq.pop(); } return os << '}';}
template<size_t N>ostream& operator<<(ostream& os, const bitset<N>& bs) { return os << bs.to_string();}

void debug_out() { cout << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << ' ' << H; debug_out(T...); }
#ifdef LOCAL_DEBUG
  #define debug(...) cout << "[Line " <<  __LINE__ << "] (" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
  #define debug(...)
#endif

/*
  
*/

const int MAXN = 1e6;
vector<int> primes, spf, res;
vector<vector<int>> pfstore;

void precompute() {
  spf.resize(MAXN + 1);
  for (int i = 2; i <= MAXN; i++) {
    if (spf[i] == 0) {
      spf[i] = i;
      primes.push_back(i);
    }
    for (int j = 0; i * primes[j] <= MAXN; j++) {
      spf[i * primes[j]] = primes[j];
      if (primes[j] == spf[i]) {
        break;
      }
    }
  }
  
  pfstore.resize(MAXN + 1);
  for (int i = 2; i <= MAXN; i++) {
    int x = i;
    while (x > 1) {
      int p = spf[x];
      pfstore[i].push_back(p);
      x /= p;
    }
  }
  
  int maxDiv = 0, best = -1;
  res.resize(MAXN + 1);
  for (int i = 1; i <= MAXN; i++) {
    // int sum = i * (i + 1) / 2
    map<int, int> pfacs;
    for (auto& p : pfstore[i]) {
      pfacs[p]++;
    }
    for (auto& p : pfstore[i + 1]) {
      pfacs[p]++;
    }
    pfacs[2]--;
    
    int div = 1;
    for (auto& [p, e] : pfacs) {
      div *= (e + 1);
    }
    
    // debug(i, div, maxDiv, pfacs);
    if (div >= maxDiv) {
      maxDiv = div;
      best = i;
    }
    res[i] = maxDiv;
  }
}

void run_case() {
  int n;
  cin >> n;
  cout << res[n] << '\n';
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin.exceptions(cin.failbit);
  
  precompute();

  int T = 1;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    // cout << "Case #" << t << ": ";
    run_case();
  }

  return 0;
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Contest
Brain Booster #9
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 17:35:51
Judged At
2025-04-06 17:35:51
Judged By
Score
100
Total Time
552ms
Peak Memory
90.328 MiB