/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 576ms 89.223 MiB
#2 Accepted 595ms 89.414 MiB
#3 Accepted 580ms 89.578 MiB
#4 Accepted 565ms 89.52 MiB
#5 Accepted 566ms 89.699 MiB
#6 Accepted 560ms 89.566 MiB

Code

/**
 *    author:   Binoy Barman
 *    created:  2025-04-07 12:20:06
**/

#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
}
}

const int N = 1e6 + 5;

int spf[N];
void sieve() {
    for (int i = 2; i < N; i++) spf[i] = i;
    for (int i = 2; i * i < N; i++) {
        if (spf[i] == i) { // prime
            for (int j = i * i; j < N; j += i) {
                spf[j] = min(spf[j], i);
            }
        }
    }
}

int ans[N];
vector<int> pf[N];
void prime_factors(int n) {
    int x = n;
    while(n != 1) {
        pf[x].push_back(spf[n]);
        n = n / spf[n];
    }
}

void prec() {
    sieve();
    for (int i = 1; i < N; i++) prime_factors(i);
    for (int i = 1; i + 1 < N; i++) {
        map<int, int> f;
        for(auto x : pf[i]) f[x]++;
        for(auto x : pf[i + 1]) f[x]++;
        f[2]--;
        int divs = 1;
        for(auto it : f) divs *= it.second + 1;
        ans[i] = max(ans[i - 1], divs);
    }
}

int32_t main() {
    Dark_Lord_Binoy::init();
    prec();
    Testcase_Handler {
        int n;
        cin >> n;
        cout << ans[n] << nl;
    }

    dbg(_Time_);
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-07 07:31:24
Judged At
2025-04-07 07:31:24
Judged By
Score
100
Total Time
595ms
Peak Memory
89.699 MiB