/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 37ms 8.172 MiB
#2 Accepted 53ms 8.52 MiB
#3 Accepted 52ms 8.52 MiB
#4 Accepted 48ms 8.617 MiB
#5 Accepted 51ms 8.52 MiB
#6 Accepted 48ms 8.562 MiB

Code

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
const int MAX = 1000001; // We'll compute divisor counts up to 1e6+1.
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    // Precompute number of divisors for every number from 1 to MAX.
    vector<int> divCount(MAX+1, 0);
    for (int i = 1; i <= MAX; i++){
        for (int j = i; j <= MAX; j += i){
            divCount[j]++;
        }
    }
    
    // Precompute maximum divisors of S(L) for L from 1 to maxN.
    // Given constraints, maximum N can be up to 1e6.
    const int maxN = 1000000;
    vector<int> best(maxN+1, 0);
    
    // For L=0 (not used) but for L>=1:
    int currMax = 0;
    for (int L = 1; L <= maxN; L++){
        int dS;
        if(L % 2 == 0){
            // S(L) = (L/2) * (L+1)
            dS = divCount[L/2] * divCount[L+1];
        } else {
            // S(L) = L * ((L+1)/2)
            dS = divCount[L] * divCount[(L+1)/2];
        }
        currMax = max(currMax, dS);
        best[L] = currMax;
    }
    
    // Process test cases.
    int t;
    cin >> t;
    while(t--){
        int N;
        cin >> N;
        cout << best[N] << "\n";
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Language
C++17 (G++ 13.2.0)
Submit At
2025-03-27 20:27:09
Judged At
2025-03-27 20:27:09
Judged By
Score
100
Total Time
53ms
Peak Memory
8.617 MiB