Language: C++

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct frep {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr frep(int l_, int r_): l(std::min(l_, r_)), r(r_) {}
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct brep {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr brep(int l_, int r_): r(std::max(l_, r_) - 1), l(l_ - 1) {}
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
inline T scan() {
  T res;
  std::cin >> res;
  return res;
}

using lint = long long;

int main() {
  const int N = scan<int>();
  std::unordered_map<lint, int> count;
  std::unordered_map<lint, bool> used;
  for (int i: frep(0, N)) {
    lint x, max;
    std::cin >> x;
    for (lint t = 1; t * t * t <= x; ++t) {
      if (x % (t * t * t) == 0) {
        max = t;
      }
    }
    count[x / (max * max * max)]++;
  }
  int ans = 0;
  for (auto p: count) {
    if (p.first == 1) {
      ++ans;
      used[p.first] = true;
      continue;
    }
    lint max;
    for (lint t = 1; t * t * t < p.first; ++t) {
      if (p.first % (t * t) == 0) {
        max = t;
      }
    }
    lint nx = p.first / (max * max);
    if (nx <= 10000000000ll / (nx * max)) {
      lint y = nx * nx * max;
      if (count.find(y) != count.end()) {
        ans += std::max(p.second, count[y]);
        used[p.first] = true;
        used[y] = true;
      }
    }
    if (!used[p.first]) {
      ans += p.second;
      used[p.first] = true;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:66:8: error: 'unordered_map' is not a member of 'std'
   66 |   std::unordered_map<lint, int> count;
      |        ^~~~~~~~~~~~~
a.cc:6:1: note: 'std::unordered_map' is defined in header '<unordered_map>'; this is probably fixable by adding '#include <unordered_map>'
    5 | #include <map>
  +++ |+#include <unordered_map>
    6 | 
a.cc:66:26: error: expected primary-expression before ',' token
   66 |   std::unordered_map<lint, int> count;
      |                          ^
a.cc:66:28: error: expected primary-expression before 'int'
   66 |   std::unordered_map<lint, int> count;
      |                            ^~~
a.cc:67:8: error: 'unordered_map' is not a member of 'std'
   67 |   std::unordered_map<lint, bool> used;
      |        ^~~~~~~~~~~~~
a.cc:67:8: note: 'std::unordered_map' is defined in header '<unordered_map>'; this is probably fixable by adding '#include <unordered_map>'
a.cc:67:26: error: expected primary-expression before ',' token
   67 |   std::unordered_map<lint, bool> used;
      |                          ^
a.cc:67:28: error: expected primary-expression before 'bool'
   67 |   std::unordered_map<lint, bool> used;
      |                            ^~~~
a.cc:76:5: error: 'count' was not declared in this scope; did you mean 'std::count'?
   76 |     count[x / (max * max * max)]++;
      |     ^~~~~
      |     std::count
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:2:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: 'std::count' declared here
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
a.cc:79:16: error: 'count' was not declared in this scope; did you mean 'std::count'?
   79 |   for (auto p: count) {
      |                ^~~~~
      |                std::count
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: 'std::count' declared here
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
a.cc:82:7: error: 'used' was not declared in this scope
   82 |       used[p.first] = true;
      |       ^~~~
a.cc:96:9: error: 'used' was not declared in this scope
   96 |         used[p.first] = true;
      |         ^~~~
a.cc:100:10: error: 'used' was not declared in this scope
  100 |     if (!used[p.first]) {
      |          ^~~~