/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 19ms 7.965 MiB
#2 Time Exceeded ≥2597ms ≥8.02 MiB
#3 Time Exceeded ≥2596ms ≥8.02 MiB

Code

#include <bits/stdc++.h>
#define ll long long
#define N "\n"
using namespace std;

const ll MAXN = 1e6 + 10;
vector<ll> spf(MAXN);

void sieve()
{
      for (ll i = 2; i < MAXN; i++)
      {
            if (spf[i] == 0)
            {
                  for (ll j = i; j < MAXN; j += i)
                  {
                        if (spf[j] == 0)
                              spf[j] = i;
                  }
            }
      }
}

unordered_map<ll, ll> factorize(ll x)
{
      unordered_map<ll, ll> fact;
      while (x >= MAXN)
      {
            bool found = false;
            for (ll i = 2; i * i <= x; i++)
            {
                  if (x % i == 0)
                  {
                        ll count = 0;
                        while (x % i == 0)
                        {
                              count++;
                              x /= i;
                        }
                        fact[i] += count;
                        found = true;
                        break;
                  }
            }
            if (!found)
            {
                  fact[x]++;
                  return fact;
            }
      }
      while (x > 1)
      {
            fact[spf[x]]++;
            x /= spf[x];
      }
      return fact;
}

ll countdiv(unordered_map<ll, ll> &fact)
{
      ll div = 1;
      for (auto &[p, e] : fact)
      {
            div *= (e + 1);
      }
      return div;
}

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      sieve();

      ll t;
      cin >> t;
      while (t--)
      {
            ll n;
            cin >> n;
            ll mx = 0;
            for (ll i = 1; i <= n; i++)
            {
                  ll a = i;
                  ll b = i + 1;
                  if (a % 2 == 0)
                        a /= 2;
                  else
                        b /= 2;

                  unordered_map<ll, ll> f1 = factorize(a);
                  unordered_map<ll, ll> f2 = factorize(b);

                  for (auto &[p, e] : f2)
                        f1[p] += e;

                  ll divs = countdiv(f1);
                  mx = max(mx, divs);
            }
            cout << mx << N;
      }
      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:20:03
Judged At
2025-04-06 17:20:03
Judged By
Score
0
Total Time
≥2597ms
Peak Memory
≥8.02 MiB