Untitled

 avatar
user_5668965
c_cpp
a year ago
1.6 kB
12
Indexable
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define float long double
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("Ofast")
#ifndef ONLINE_JUDGE
#include "dbg.hpp"
#else
#define debug(...) 8
#endif

void solve(){
    int n;
    cin>>n;
    int tmp=n;
    map<int,int> mapi;
    for(int i=2;i*i<=n;i++){
        int cnt=0;
        while(tmp%i==0 && tmp>0){
            tmp/=i;
            cnt++;
        }
        if(cnt>0){
            mapi[i]=cnt;
        }
    }
    int maxi=1;
    for(auto it:mapi){
        maxi=max(it.second,maxi);
    }
    if(tmp>1){
        mapi[tmp]=1;
    }
    // debug(mapi,maxi);
    int ans=0;
    for(int i=0;i<maxi;i++){
        int ok=1;
        for(auto it:mapi){
            if(it.second<=0) continue;
            mapi[it.first]--;
            ok*=it.first;
            if(it.second==0){
                mapi.erase(it.first);
            }
            // debug(ok);
        }
        
        ans+=ok;
    }
    cout<<ans<<'\n';
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin>>t;
    while (t--)
    {
        solve();
    }
}
Editor is loading...
Leave a Comment