/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error 10ms 8.27 MiB
#2 Runtime Error 30ms 8.336 MiB

Code

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

const int N = 1e6 + 2;
vector<int> spf(N + 1);
vector<int> max_divisors(N + 1, 0);

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

int num_divisors(int x) {
    if (x == 1) return 1;
    int res = 1;
    while (x > 1) {
        int p = spf[x];
        int count = 0;
        while (x % p == 0) {
            x /= p;
            count++;
        }
        res *= (count + 1);
    }
    return res;
}

void precompute() {
    sieve();
    int current_max = 0;
    for (int L = 1; L <= N; ++L) {
        int S = L * (L + 1) / 2;
        int divisors = num_divisors(S);
        if (divisors > current_max) {
            current_max = divisors;
        }
        max_divisors[L] = current_max;
    }
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    precompute();
    int tt;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 20:34:51
Judged At
2025-04-06 20:34:51
Judged By
Score
0
Total Time
30ms
Peak Memory
8.336 MiB