Language: C++

#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <cfloat>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double l_double;

#define gcd __gcd
#define FFS(var) __builtin_ffs(var)
#define CLZ(var) __builtin_clz(var)
#define CTZ(var) __builtin_ctz(var)
#define POPCOUNT(var) __builtin_popcount(var)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define s_cast static_cast // <>
#define deb(x) cerr << "(" << #x << ") -> (" << x << ") "
#define deb2(x,y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") "
#define deb3(x,y,z) cerr << "(" << #x << ", " << #y << ", " << #z << ") -> (" << x << ", " << y << ", " << z << ") "
#define debVV(V) cerr << #V << ":\n" << V << endl; // 2D

const double PI {3.1415926535897932384626433832795};
const int MOD {static_cast<int>(1e9 + 7)};
const double EPS {1e-9};

// 1D-----------------------------------------------------
template<typename T, size_t N>  // array extraction
istream& operator>>(istream &is, array<T, N> &ARR) {
    for (T &a: ARR) is >> a;
    return is;
}

template<typename T, size_t N>  // array insertion
ostream& operator<<(ostream &os, array<T, N> &ARR) {
    for (T const &a: ARR) os << a << " ";
    return os;
}

template<typename T>  // vector extraction
istream& operator>>(istream &is, vector<T> &VEC) {
    for (T &v: VEC) is >> v;
    return is;
}

template <typename T>  // vector insertion
ostream& operator<<(ostream &os, const vector<T> &VEC) {
    for (T const &v: VEC) os << v << " ";
    return os;
}

template<typename T>  // deque extraction
istream& operator>>(istream &is, deque<T> &DEQ) {
    for (T &d: DEQ) is >> d;
    return is;
}

template<typename T>  // deque insertion
ostream& operator<<(ostream &os, const deque<T> &DEQ) {
    for (const T &d: DEQ) os << d << " ";
    return os;
}

template<typename T>  // list extraction
istream& operator>>(istream &is, list<T> &LIS) {
    for (T &l: LIS) is >> l;
    return is;
}

template<typename T>  // list insertion
ostream& operator<<(ostream &os, const list<T> &LIS) {
    for (T const &l: LIS) os << l << " ";
    return os;
}

template<typename T>  // set insertion
ostream& operator<<(ostream &os, const set<T> &ST) {
    for (auto const &s: ST) os << s << " ";
    return os;
}

template<typename T>  // unordered_set insertion
ostream& operator<<(ostream &os, const unordered_set<T> &U_ST) {
    for (T const &us: U_ST) os << us << " ";
    return os;
}

template<typename T1, typename T2>  // pair extraction
istream& operator>>(istream &is, pair<T1, T2> &PR) {
    is >> PR.first >> PR.second;
    return is;
}

template<typename T1, typename T2>  // pair debug
ostream& operator<<(ostream &os, const pair<T1, T2> &PR) {
    os << "[" << PR.first << ": " << PR.second << "]";
    return os;
}

template<typename T1, typename T2>  // map debug
ostream& operator<<(ostream &os, const map<T1, T2> &MP) {
    os << "[ ";
    for (pair<T1, T2> const &m: MP) os << m << " ";
    os << "]";
    return os;
}

template<typename T1, typename T2>  // unordered_map debug
ostream& operator<<(ostream& os, const unordered_map<T1, T2> &U_MP) {
    os << "[ ";
    for (pair<T1, T2> const &um: U_MP) os << um << " ";
    os << "]";
    return os;
}

template<typename T>  // stack debug
ostream& operator<<(ostream &os, stack<T> STACK) {
    while (!STACK.empty()) {
        os << STACK.top() << " ";
        STACK.pop();
    }
    return os;
}

template<typename T>  // queue debug
ostream& operator<<(ostream &os, queue<T> QUEUE) {
    while (!QUEUE.empty()) {
        os << QUEUE.front() << " ";
        QUEUE.pop();
    }
    return os;
}

// 2D----------------------------------------------------------------
template<typename T, size_t R, size_t C>  // 2D array extraction
istream& operator<<(istream &is, array<array<T, C>, R> &MAT) {
    for (array<T, C> &ROW: MAT) cin >> ROW;
    return is;
}

template<typename T, size_t R, size_t C>  // 2D array insertion
ostream& operator<<(ostream &os, array<array<T, C>, R> &MAT) {
    for (array<T, C> &ROW: MAT) os << ROW << endl;
    return os;
}

template<typename T>  // 2D vector extraction
istream& operator>>(istream &is, vector<vector<T>> &MAT) {
    for (vector<T> &ROW: MAT) is >> ROW;
    return is;
}

template<typename T>  // 2D vector insertion
ostream& operator<<(ostream &os, vector<vector<T>> &MAT) {
    for (vector<T> &ROW: MAT) os << ROW << endl;
    return os;
}

template<typename T>
T max(const T &A, const T &B, const T &C) {
    T mx {A};
    (mx < B) && (mx = B);
    (mx < C) && (mx = C);
    return mx;
}

template<typename T>
T min(const T &A, const T &B, const T &C) {
    T mn {A};
    (mn > B) && (mn = B);
    (mn > C) && (mn = C);
    return mn;
}

template<typename T>
int cntDigits(const T &N) { return (static_cast<int>(log10(N)) + 1); }

template<typename T>
bool isPowOfTwo(const T &N) { return (N && (!(N&(N-1)))); }

template<typename T>
bool dblEqual(const T &a, const T &b) {
    return abs(a - b) < EPS;
}

/* -------------------------------------------------------- */
/* -------------------------------------------------------- */

array<bool, s_cast<int>(1e6 + 1)> ref {};
unordered_map<int, int> freq {};

void Sieve(const vector<int> &arr) {
    for (int i {}; i < static_cast<int>(arr.size()); ++i) {
        if (ref.at(arr.at(i))) {
            for (int j {i+1}; j < static_cast<int>(arr.size()); ++j)
                if (!(arr.at(j)%arr.at(i)))
                    ref.at(arr.at(j)) = false;
        }
        if (freq.at(arr.at(i)) > 1) ref.at(arr.at(i)) = false;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cerr.setf(std::ios::boolalpha);
    cout << std::fixed;
    cout << std::setprecision(6); // default
    /* ---------------------------------- */

    ref.fill(true);

    int n {};
    cin >> n;
    vector<int> arr (n);
    for (int i {}; i < n; ++i) {
        cin >> arr.at(i);
        freq[arr.at(i)]++;
    }
    sort(arr.begin(), arr.end());

    Sieve(arr);

    int ans {};
    for (auto const &val: arr) {
        if (ref.at(val))
            ++ans;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'void Sieve(const std::vector<int>&)':
a.cc:214:13: error: reference to 'ref' is ambiguous
  214 |         if (ref.at(arr.at(i))) {
      |             ^~~
In file included from /usr/include/c++/14/string:52,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:209:35: note:                 'std::array<bool, 1000001> ref'
  209 | array<bool, s_cast<int>(1e6 + 1)> ref {};
      |                                   ^~~
a.cc:217:21: error: reference to 'ref' is ambiguous
  217 |                     ref.at(arr.at(j)) = false;
      |                     ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:209:35: note:                 'std::array<bool, 1000001> ref'
  209 | array<bool, s_cast<int>(1e6 + 1)> ref {};
      |                                   ^~~
a.cc:219:37: error: reference to 'ref' is ambiguous
  219 |         if (freq.at(arr.at(i)) > 1) ref.at(arr.at(i)) = false;
      |                                     ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:209:35: note:                 'std::array<bool, 1000001> ref'
  209 | array<bool, s_cast<int>(1e6 + 1)> ref {};
      |                                   ^~~
a.cc: In function 'int32_t main()':
a.cc:231:5: error: reference to 'ref' is ambiguous
  231 |     ref.fill(true);
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:209:35: note:                 'std::array<bool, 1000001> ref'
  209 | array<bool, s_cast<int>(1e6 + 1)> ref {};
      |                                   ^~~
a.cc:246:13: error: reference to 'ref' is ambiguous
  246 |         if (ref.at(val))
      |             ^~~
/usr/include/c++/14/bits/refwrap.h:445:5: note: candidates are: 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(reference_wrapper<_Tp>)'
  445 |     ref(reference_wrapper<_Tp> __t) noexcept
      |     ^~~
/usr/include/c++/14/bits/refwrap.h:436:10: note:                 'template<class _Tp> void std::ref(const _Tp&&)'
  436 |     void ref(const _Tp&&) = delete;
      |          ^~~
/usr/include/c++/14/bits/refwrap.h:425:5: note:                 'template<class _Tp> std::reference_wrapper<_Tp> std::ref(_Tp&)'
  425 |     ref(_Tp& __t) noexcept
      |     ^~~
a.cc:209:35: note:                 'std::array<bool, 1000001> ref'
  209 | array<bool, s_cast<int>(1e6 + 1)> ref {};
      |                                   ^~~