/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 285ms 18.645 MiB
#2 Accepted 300ms 18.703 MiB
#3 Wrong Answer 325ms 19.32 MiB
#4 Accepted 300ms 19.555 MiB
#5 Wrong Answer 308ms 18.828 MiB

Code

/**
 *    author:   Binoy Barman
 *    created:  2025-04-06 22:09:32
**/

#include<bits/stdc++.h>
#ifdef LOCAL
#include "algo/debug.h"
#else
#define dbg(...) 42
#endif
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = 2e9;

#define int long long
#define nl '\n'
#define all(v) v.begin(), v.end()
#define clg(x) (32 - __builtin_clz(x))
#define Testcase_Handler int tts, tc = 0; cin >> tts; hell: while(tc++ < tts)
#define uniq(v) sort(all(v)), v.resize(distance(v.begin(), unique(v.begin(), v.end())))
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename A, typename B> istream& operator>>(istream& in, pair<A, B>& p) {in >> p.first >> p.second; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {bool first = true;for(auto &x : a) {if(!first) out << ' ';first = false;out << x;}return out;};

namespace Dark_Lord_Binoy {
inline void init() {
    ios::sync_with_stdio(false); 
    cin.tie(nullptr);

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
}

namespace PollardRho {
    mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
    const int P = 1e6 + 9;
    ll seq[P];
    int primes[P], spf[P];
    inline ll add_mod(ll x, ll y, ll m) {
        return (x += y) < m ? x : x - m;
    }
    inline ll mul_mod(ll x, ll y, ll m) {
        // ll res = __int128(x) * y % m;
        // return res;
        ll res = x * y - (ll)((long double)x * y / m + 0.5) * m;
        return res < 0 ? res + m : res;
    }
    inline ll pow_mod(ll x, ll n, ll m) {
        ll res = 1 % m;
        for (; n; n >>= 1) {
            if (n & 1) res = mul_mod(res, x, m);
            x = mul_mod(x, x, m);
        }
        return res;
    }
    // O(it * (logn)^3), it = number of rounds performed
    inline bool miller_rabin(ll n) {
        if (n <= 2 || (n & 1 ^ 1)) return (n == 2);
        if (n < P) return spf[n] == n;
        ll c, d, s = 0, r = n - 1;
        for (; !(r & 1); r >>= 1, s++) {}
        // each iteration is a round
        for (int i = 0; primes[i] < n && primes[i] < 32; i++) {
            c = pow_mod(primes[i], r, n);
            for (int j = 0; j < s; j++) {
                d = mul_mod(c, c, n);
                if (d == 1 && c != 1 && c != (n - 1)) return false;
                c = d;
            }
            if (c != 1) return false;
        }
        return true;
    }
    void init() {
        int cnt = 0;
        for (int i = 2; i < P; i++) {
            if (!spf[i]) primes[cnt++] = spf[i] = i;
            for (int j = 0, k; (k = i * primes[j]) < P; j++) {
                spf[k] = primes[j];
                if (spf[i] == spf[k]) break;
            }
        }
    }
    // returns O(n^(1/4))
    ll pollard_rho(ll n) {
        while (1) {
            ll x = rnd() % n, y = x, c = rnd() % n, u = 1, v, t = 0;
            ll *px = seq, *py = seq;
            while (1) {
                *py++ = y = add_mod(mul_mod(y, y, n), c, n);
                *py++ = y = add_mod(mul_mod(y, y, n), c, n);
                if ((x = *px++) == y) break;
                v = u;
                u = mul_mod(u, abs(y - x), n);
                if (!u) return __gcd(v, n);
                if (++t == 32) {
                    t = 0;
                    if ((u = __gcd(u, n)) > 1 && u < n) return u;
                }
            }
            if (t && (u = __gcd(u, n)) > 1 && u < n) return u;
        }
    }
    vector<ll> factorize(ll n) {
        if (n == 1) return vector <ll>();
        if (miller_rabin(n)) return vector<ll> {n};
        vector<ll> v, w;
        while (n > 1 && n < P) {
            v.push_back(spf[n]);
            n /= spf[n];
        }
        if (n >= P) {
            ll x = pollard_rho(n);
            v = factorize(x);
            w = factorize(n / x);
            v.insert(v.end(), w.begin(), w.end());
        }
        return v;
    }
}

const int N = 1e5 + 5, MAXN = 1e6 + 5;
int ans[MAXN];

int divisors(long long n) {
    auto pf = PollardRho::factorize(n);
    map<int, int> f;
    for(auto x : pf) {
        f[x]++;
    }
    int divs = 1;
    for(auto it : f) {
        divs *= (1 + it.second);
    }
    return divs;
}

void prec() {
    PollardRho::init();
    memset(ans, -1, sizeof ans);
    int sum = 0;
    ans[0] = 0;
    for (int i = 1; i < N; i++) {
        sum += i;
        int cur = divisors(sum);
        ans[i] = max(ans[i - 1], cur);
    }
}

int32_t main() {
    Dark_Lord_Binoy::init();
    prec();
    Testcase_Handler {
        int n;
        cin >> n;
        if(n <= N) {
            cout << ans[n] << nl;
            goto hell;
        }
        int cur = 0;
        for (int i = n; i >= n - 100; i--) {
            if(ans[i] != -1) {
                ans[n] = max(ans[n], ans[i]);
                break;
            }
            int sum = (i * (i + 1)) / 2LL;
            auto pf = PollardRho::factorize(n);
            map<int, int> f;
            for(auto x : pf) {
                f[x]++;
            }
            int divs = 1;
            for(auto it : f) {
                divs *= (1 + it.second);
            }
            ans[i] = max(divs, ans[i + 1]);
        }
        cout << ans[n] << nl;
    }

    dbg(_Time_);
    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:45:00
Judged At
2025-04-06 17:45:00
Judged By
Score
40
Total Time
325ms
Peak Memory
19.555 MiB