Language: C++

#include<bits/stdc++.h>
#define lim 2154
#define ll long long
using namespace std;
ll a[100010];
ll b[100010];
ll p[100010];
map<ll,ll> vis;
map<ll,ll> cnt1;
map<ll,ll> sqr;
map<ll,ll> root;
vector<ll> v;

void sieve()
{
    ll i,j,k,l;
    sqr[1]=1;
    root[1]=1;
    for(i=2;i<=100000;i++)
    {
        if(p[i]) continue;
        sqr[i*i]=1;
        root[i*i]=i;
        v.push_back(i);
//        cout<<v.size()<<' ';
        for(j=i*i;j<=100000;j+=i)
        {
            p[j]=1;
        }
    }
}

ll x,y;
void get1(ll s)
{
    ll i,j,k,l;
    x=y=1;
    for(i=0;i<v.size()&&v[i]<lim;i++)
    {
        k=0;
        ll u=v[i];
        while(s%u==0)
        {
            s/=u;
            k++;
            k%=3;
        }
        l=(3-k)%3;
        while(k--) x*=u;
        while(l--) y*=u;
    }

    if(s!=1)
    {
        if(sqr[s])
        {
            x*=s;
            y*=root[s];
        }
        else
        {
            x*=s;
            y*=s*s;
        }
    }
}

int main()
{
    ll n;
    sieve();
    cin>>n;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        get1(a[i]);
//        cout<<a[i]<<' '<<x<<' '<<y<<'\n';
        a[i]=x;
        b[i]=y;
        cnt1[x]++;
    }

    for(int i=0;i<n;i++)
    {
        if(vis[a[i]]) continue;
        if(a[i]==1) ans++;
        else ans+=max(cnt1[a[i]],cnt1[b[i]]);
        vis[a[i]]=vis[b[i]]=1;
    }

    cout<<ans;
}



//6
//1 1 2 2 4 4
//ans: 3

//10
//1 1 2 2 4 4 4 4 4 4
//ans: 7

//10
//1 1 2 2 2 2 2 2 4 4
#include<bits/stdc++.h>
#define lim 2154
#define ll long long
using namespace std;
ll a[100010];
ll b[100010];
ll p[100010];
map<ll,ll> vis;
map<ll,ll> cnt1;
map<ll,ll> sqr;
map<ll,ll> root;
vector<ll> v;

void sieve()
{
    ll i,j,k,l;
    sqr[1]=1;
    root[1]=1;
    for(i=2;i<=100000;i++)
    {
        if(p[i]) continue;
        sqr[i*i]=1;
        root[i*i]=i;
        v.push_back(i);
//        cout<<v.size()<<' ';
        for(j=i*i;j<=100000;j+=i)
        {
            p[j]=1;
        }
    }
}

ll x,y;
void get1(ll s)
{
    ll i,j,k,l;
    x=y=1;
    for(i=0;i<v.size()&&v[i]<lim;i++)
    {
        k=0;
        ll u=v[i];
        while(s%u==0)
        {
            s/=u;
            k++;
            k%=3;
        }
        l=(3-k)%3;
        while(k--) x*=u;
        while(l--) y*=u;
    }

    if(s!=1)
    {
        if(sqr[s])
        {
            x*=s;
            y*=root[s];
        }
        else
        {
            x*=s;
            y*=s*s;
        }
    }
}

int main()
{
    ll n;
    sieve();
    cin>>n;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        get1(a[i]);
//        cout<<a[i]<<' '<<x<<' '<<y<<'\n';
        a[i]=x;
        b[i]=y;
        cnt1[x]++;
    }

    for(int i=0;i<n;i++)
    {
        if(vis[a[i]]) continue;
        if(a[i]==1) ans++;
        else ans+=max(cnt1[a[i]],cnt1[b[i]]);
        vis[a[i]]=vis[b[i]]=1;
    }

    cout<<ans;
}



//6
//1 1 2 2 4 4
//ans: 3

//10
//1 1 2 2 4 4 4 4 4 4
//ans: 7

//10
//1 1 2 2 2 2 2 2 4 4


Compiler output:
a.cc:111:4: error: redefinition of 'long long int a [100010]'
  111 | ll a[100010];
      |    ^
a.cc:5:4: note: 'long long int a [100010]' previously declared here
    5 | ll a[100010];
      |    ^
a.cc:112:4: error: redefinition of 'long long int b [100010]'
  112 | ll b[100010];
      |    ^
a.cc:6:4: note: 'long long int b [100010]' previously declared here
    6 | ll b[100010];
      |    ^
a.cc:113:4: error: redefinition of 'long long int p [100010]'
  113 | ll p[100010];
      |    ^
a.cc:7:4: note: 'long long int p [100010]' previously declared here
    7 | ll p[100010];
      |    ^
a.cc:114:12: error: redefinition of 'std::map<long long int, long long int> vis'
  114 | map<ll,ll> vis;
      |            ^~~
a.cc:8:12: note: 'std::map<long long int, long long int> vis' previously declared here
    8 | map<ll,ll> vis;
      |            ^~~
a.cc:115:12: error: redefinition of 'std::map<long long int, long long int> cnt1'
  115 | map<ll,ll> cnt1;
      |            ^~~~
a.cc:9:12: note: 'std::map<long long int, long long int> cnt1' previously declared here
    9 | map<ll,ll> cnt1;
      |            ^~~~
a.cc:116:12: error: redefinition of 'std::map<long long int, long long int> sqr'
  116 | map<ll,ll> sqr;
      |            ^~~
a.cc:10:12: note: 'std::map<long long int, long long int> sqr' previously declared here
   10 | map<ll,ll> sqr;
      |            ^~~
a.cc:117:12: error: redefinition of 'std::map<long long int, long long int> root'
  117 | map<ll,ll> root;
      |            ^~~~
a.cc:11:12: note: 'std::map<long long int, long long int> root' previously declared here
   11 | map<ll,ll> root;
      |            ^~~~
a.cc:118:12: error: redefinition of 'std::vector<long long int> v'
  118 | vector<ll> v;
      |            ^
a.cc:12:12: note: 'std::vector<long long int> v' previously declared here
   12 | vector<ll> v;
      |            ^
a.cc:120:6: error: redefinition of 'void sieve()'
  120 | void sieve()
      |      ^~~~~
a.cc:14:6: note: 'void sieve()' previously defined here
   14 | void sieve()
      |      ^~~~~
a.cc:139:4: error: redefinition of 'long long int x'
  139 | ll x,y;
      |    ^
a.cc:33:4: note: 'long long int x' previously declared here
   33 | ll x,y;
      |    ^
a.cc:139:6: error: redefinition of 'long long int y'
  139 | ll x,y;
      |      ^
a.cc:33:6: note: 'long long int y' previously declared here
   33 | ll x,y;
      |      ^
a.cc:140:6: error: redefinition of 'void get1(long long int)'
  140 | void get1(ll s)
      |      ^~~~
a.cc:34:6: note: 'void get1(long long int)' previously defined here
   34 | void get1(ll s)
      |      ^~~~
a.cc:174:5: error: redefinition of 'int main()'
  174 | int main()
      |     ^~~~
a.cc:68:5: note: 'int main()' previously defined here
   68 | int main()
      |     ^~~~