/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 12ms 1.34 MiB
#2 Time Exceeded ≥1100ms ≥15.77 MiB
#3 Time Exceeded ≥1100ms ≥16.363 MiB

Code

// Created: 2025-07-14 22:23:33 IST
#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;
// #define int long long
#define ll long long
#define cout cout<<fixed<<setprecision(0)
#define pb push_back
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(a,n) for(int i=0; i<n; i++){ cin>>a[i]; }
#define ff(a,l,n) for(int i=l; i<=n; i++){ cin>>a[i]; }
#define vvi vector<vector<int>>
#define vi vector<int>
#define all(a) (a).begin(), (a).end()
#define minpq priority_queue<ll, vector<ll>, greater<ll>> ;
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void SieveOfEratosthenes(int n, bool prime[],
                         bool primesquare[], int a[])
{
    
    
    for (int i = 2; i <= n; i++)
        prime[i] = true;

    for (int i = 0; i <= (n * n + 1); i++)
        primesquare[i] = false;

   
    prime[1] = false;

    for (int p = 2; p * p <= n; p++) {
        if (prime[p] == true) {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }

    int j = 0;
    for (int p = 2; p <= n; p++) {
        if (prime[p]) {
            a[j] = p;
            primesquare[p * p] = true;
            j++;
        }
    }
}
int countDivisors(int n)
{
 
    if (n == 1)
        return 1;

    bool prime[n + 1], primesquare[n * n + 1];

    int a[n];

    
    SieveOfEratosthenes(n, prime, primesquare, a);

    
    int ans = 1;

    
    for (int i = 0;; i++) {
    
        if (a[i] * a[i] * a[i] > n)
            break;

    
        int cnt = 1; 
        while (n % a[i] == 0) 
        {
            n = n / a[i];
            cnt = cnt + 1; 
        }

        ans = ans * cnt;
    }




    if (prime[n])
        ans = ans * 2;


    else if (primesquare[n])
        ans = ans * 3;


    else if (n != 1)
        ans = ans * 4;

    return ans;
}
void solve(){
    int n; cin>>n;
    ll ans=0;
    for(int i=1; i<=n; ++i){
        ans+=countDivisors(i)-1;
    }
    cout<<ans<<endl;
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    // solve();
    int t; cin>>t;
    for(int i=0; i<t; i++){
        solve();
    }
    
    
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    // cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0; 
}

Information

Submit By
Type
Submission
Problem
P1206 D1. GCD equal Absolute Value (Easy Version)
Contest
Educational Round 1
Language
C++17 (G++ 13.2.0)
Submit At
2025-07-14 17:59:20
Judged At
2025-07-14 17:59:20
Judged By
Score
0
Total Time
≥1100ms
Peak Memory
≥16.363 MiB