/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 67ms 15.703 MiB
#2 Accepted 84ms 16.113 MiB
#3 Accepted 84ms 16.312 MiB
#4 Accepted 81ms 16.066 MiB
#5 Accepted 82ms 16.27 MiB
#6 Accepted 81ms 16.316 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int sz = 8e5 , mx = 1e6 + 5;
bool notPrime[sz] ;
vector< int > prime;
ll Ans[mx] , divisor[mx] ;
void seive()
{
    for(int  i = 4 ; i < sz ; i += 2) notPrime[i] = 1 ;
    int k = sqrt(sz);
    for(int i = 3 ; i < k ; i += 2)
    {
        for(int j = i*i ; j < sz ; j += i) notPrime[j] = 1 ;
    }
    prime.pb(2) ;
    for(int i = 3  ; i < sz ; i += 2) if(!notPrime[i]) prime.pb(i) ;
}
ll NumberOfDivisor(ll n)
{
    ll cnt = 1 ;
    for(int i = 0; prime[i] <= sqrt(n) && i < prime.size(); i++)
    {
        ll e = 0 ;
        if(n % prime[i] == 0)
        {
            while(n % prime[i] == 0) n /= prime[i] , e++ ;
        }
        cnt *= (e + 1) ;
    }
    if(n > 1) cnt *= 2 ;
    return cnt ;

}
void preComputeForNumberOfDivisor(){
   for(ll i = 1 ; i < mx ; i++){
       for(ll j = i  ; j < mx ; j += i) {
        divisor[j]++ ;
       }
   }
}

void preCompute(){
    ll cur = 0 ;
   for(ll i = 1 ; i <= 1e6 ; i++){
    ll a = i , b = i + 1 ;
    if(i & 1) b /= 2 ;
    else a/= 2 ;
    if (a >= mx || b >= mx) continue;
    ll sumOfOneToN = divisor[a] * divisor[b] ;
   // cout << a << " " << b << " " << sumOfOneToN << " " << cur << endl ;
    cur = max(sumOfOneToN , cur) ;
    Ans[i] = cur ;
   }
}
void solve()
{
    ll n ; cin >> n ;
    cout << Ans[n] << "\n" ;
}
int main()
{
     __Heart__
     //seive() ;
     preComputeForNumberOfDivisor() ;
     preCompute() ;
     int t ; cin >> t ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1180 Maximum Divisor
Language
C++17 (G++ 13.2.0)
Submit At
2025-03-22 01:16:56
Judged At
2025-03-22 01:16:56
Judged By
Score
100
Total Time
84ms
Peak Memory
16.316 MiB