/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 95ms 30.883 MiB
#2 Accepted 106ms 31.484 MiB
#3 Accepted 106ms 31.426 MiB
#4 Accepted 105ms 31.523 MiB
#5 Accepted 117ms 31.52 MiB
#6 Accepted 106ms 31.43 MiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;
typedef vector<pld> vpld;
 
#define int ll
#define all(it) it.begin(),it.end()
#define ord_set(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> 

int CNT[(int)1e6+2];
int PRIME[(int)1e6+2];
int RES[(int)1e6+2];
int BEST[(int)1e6+2];

void preprocess(){
    for (int i=0;i<=1e6+1;i++) PRIME[i] = i;    
    for (int i=2;i*i<=1e6+1;i++) if (PRIME[i] == i) for (int j=i*i;j<=1e6;j+=i) PRIME[j] = i;

    CNT[1] = 1;
    for (int i=2;i<=1e6+1;i++){
        int p = 1;
        int cnt = 0;
        int cur = i;
        while (cur % PRIME[i] == 0){
            cnt++;
            cur /= PRIME[i];
            p *= PRIME[i];
        }
        CNT[i] = CNT[cur] * (cnt+1);
    }

    for (int i=1;i<=1e6;i++){
        int a,b;
        if (i%2) a = i, b = (i+1)/2;
        else a = i+1, b = i/2;

        int g = 1;
        int cg;
        while ((cg=__gcd(a,b)) > 1){
            a /= cg;
            b /= cg;
            g *= cg;
        }

        RES[i] = CNT[a] * CNT[b] * CNT[g];
    }

    BEST[1] = 1;
    for (int i=2;i<=1e6;i++) BEST[i] = max(BEST[i-1],RES[i]);
}

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


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

    int n;
    cin >> n;
    while (n--) work();
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Language
C++17 (G++ 13.2.0)
Submit At
2025-04-06 23:08:24
Judged At
2025-04-06 23:08:24
Judged By
Score
100
Total Time
117ms
Peak Memory
31.523 MiB