/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1054ms 5.383 MiB
#2 Accepted 1079ms 5.75 MiB
#3 Accepted 1074ms 5.75 MiB
#4 Accepted 1091ms 5.746 MiB
#5 Accepted 1059ms 5.762 MiB
#6 Accepted 1074ms 5.754 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;
vector < int > Ans(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 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 ;
    ll sumOfOneToN = NumberOfDivisor(a) * NumberOfDivisor(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() ;
     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:00:43
Judged At
2025-03-22 01:00:43
Judged By
Score
100
Total Time
1091ms
Peak Memory
5.762 MiB