Language: C++

#include <iostream>
#include <map>
#include <functional>
#include <vector>
#include <cmath>

class Factoriser
{
    std::vector<int> factors;

public:
    using map_type = std::map<int, int>;
    
    Factoriser(int N)
    {
        factors.resize(N+1, 0);
        int sqrN = static_cast<int>(std::sqrt(N));

        for (int i = 2; i <= sqrN; ++i)
        {
            if (factors[i] == 0)
            {
                for (int j = i * 2; j <= N; j += i)
                {
                    if (factors[j] == 0)
                    {
                        factors[j] = i;
                    }
                }
            }
        }
    }

    map_type Factorise(int M) const
    {
        map_type P;
        int mm = M;

        while (factors[mm])
        {
            ++P[factors[mm]];
            mm /= factors[mm];
        }

        if (mm >= 2) ++P[mm];
        return P;
    }
    
    bool IsPrime(int M) const
    {
        return factors[M] == 0;
    }
};


///////////////////////////////////////////////////

using plist_citr_t = Factoriser::map_type::const_iterator;
using vi = std::vector<int>;

bool contains_dfs(int a, std::function<bool(int)> exists, int cur, plist_citr_t it, plist_citr_t last)
{
    if (cur == a) return false;
    if (it == last)  return exists(cur);

    auto [p, m] = *it++;
    for (int i = 0; i <= m; ++i)
    {
        bool r = contains_dfs(a, exists, cur, it, last);
        if (r) return true;
        cur *= p;
    }
    return false;
}

bool contains(int a, std::function<bool(int)> exists, const Factoriser &fac)
{
    auto plist = fac.Factorise(a);
    return contains_dfs(a, exists 1, plist.begin(), plist.end());
}

int main()
{
    int N;
    std::map<int, int> A;
    std::cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a;
        std::cin >> a;
        ++A[a];
    }

    constexpr int MAX_A = 1000000;
    std::vector<int> kusi(MAX_A+1, 0);
    for (auto [a, i] : A)
        kusi[a] = i;
        
    Factoriser fac(MAX_A);

    int ans = 0;
    if (kusi[1] > 1)
    {
        ans = 0;
    }
    else if (kusi[1] == 1)
    {
        ans = 1;
    }
    else
    {
        for (auto [a, i] : A)
        {
            if (i == 1 && !contains(a, [&A](int a){ return A.count(a) > 0; }, fac)) ++ans;
        }
    }
    std::cout << ans << std::endl;
}

Compiler output:
a.cc: In function 'bool contains(int, std::function<bool(int)>, const Factoriser&)':
a.cc:79:34: error: expected ')' before numeric constant
   79 |     return contains_dfs(a, exists 1, plist.begin(), plist.end());
      |                        ~         ^~
      |                                  )
a.cc:79:49: error: cannot convert 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} to 'int'
   79 |     return contains_dfs(a, exists 1, plist.begin(), plist.end());
      |                                      ~~~~~~~~~~~^~
      |                                                 |
      |                                                 std::map<int, int>::iterator {aka std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator}
a.cc:61:63: note:   initializing argument 3 of 'bool contains_dfs(int, std::function<bool(int)>, int, plist_citr_t, plist_citr_t)'
   61 | bool contains_dfs(int a, std::function<bool(int)> exists, int cur, plist_citr_t it, plist_citr_t last)
      |                                                           ~~~~^~~