#include using namespace std; #if __has_include() #include using mint = atcoder::modint1000000007; istream& operator>>(istream& is, mint& a) { int t; is >> t; a = t; return is; } ostream& operator<<(ostream& os, mint a) { return os << a.val(); } #endif #ifdef DEBUG #define _GLIBCXX_DEBUG #else #pragma GCC target("avx2") #pragma GCC optimize("Ofast,unroll-loops") #define cerr if (false) cerr #undef endl #define endl '\n' #endif #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(a) a.begin(), a.end() #define vec vector #undef long #define long long long template ostream& operator<<(ostream& os, vector a) { const int n = a.size(); rep(i, n) os << a[i] << " \n"[i + 1 == n]; return os; } template ostream& operator<<(ostream& os, array a) { rep(i, n) os << a[i] << " \n"[i + 1 == n]; return os; } template istream& operator>>(istream& is, vector& a) { for (T& i : a) is >> i; return is; } template bool chmin(T& x, T y) { if (x > y) { x = y; return true; } return false; } template bool chmax(T& x, T y) { if (x < y) { x = y; return true; } return false; } template void operator++(vector& a) { for (T& i : a) ++i; } template void operator--(vector& a) { for (T& i : a) --i; } template void operator++(vector& a, int) { for (T& i : a) i++; } template void operator--(vector& a, int) { for (T& i : a) i--; } void solve() { int n; cin >> n; vec a(n); cin >> a; bool two = false, three = false; for (int i : a) { two |= i % 2 == 0; three |= i % 3 == 0; } constexpr int inf = 2e5 + 1; vec cnt(inf); for (int i : a) cnt[i] = 1; a.clear(); for (int i = 0; i < inf; i++) if (cnt[i]) a.push_back(i); n = a.size(); fill(ALL(cnt), -1); for (int i = 0; i < n; i++) { cnt[a[i]] = i; } vec prime(inf, true); prime[0] = prime[1] = false; atcoder::dsu d(n); for (int i = 2; i * i < inf; i++) { if (prime[i]) { vec p; for (int j = i; j < inf; j += i) { if (cnt[j] != -1) p.push_back(cnt[j]); prime[j] = false; } for (int j = 1; j < p.size(); j++) { d.merge(p[0], p[j]); } } } auto g = d.groups(); int ans = 2 * g.size(); if (two) { chmin(ans, 2 * (int)(g.size() - 1)); } if (three) { chmin(ans, 3 * (int)(g.size() - 1)); } cout << ans << endl; } int main() { srand((unsigned)time(NULL)); cin.tie(nullptr); ios::sync_with_stdio(false); // cout << fixed << setprecision(40); int t = 1; // cin >> t; while (t--) solve(); return 0; }