#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; int one = 0; bool two = false, three = false; for (int i : a) { one += i == 1; two |= i % 2 == 0; three |= i % 3 == 0; } constexpr int inf = 2e5 + 2024; vec cnt(inf); for (int i : a) cnt[i] = 1; cnt[1] = 0; 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; atcoder::dsu d(n); for (int i = 2; i < inf; i++) { vec p; for (int j = i; j < inf; j += i) if (cnt[j] != -1) p.push_back(cnt[j]); for (int j = 1; j < p.size(); j++) d.merge(p[0], p[j]); } auto g = d.groups(); const int m = g.size() + one; int ans = 2 * m; if (m == 1) chmin(ans, 0); if (two) chmin(ans, 2 * (m - 1)); if (three) chmin(ans, 3 * (m - 1)); cout << ans << endl; return; } 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; }