#include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(0); const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; vector erathosthenes(i64 N) { vector is_prime(N + 1, 1); is_prime[0] = is_prime[1] = 0; vector ret; for (i64 i = 2; i <= N; i++) { if (!is_prime[i]) continue; ret.push_back(i); for (i64 j = i; j <= N; j += i) { is_prime[j] = 0; } } return ret; } int main() { FAST_IO int N; cin >> N; vector A(N); for (auto &v : A) cin >> v; auto primes = erathosthenes(300000); vector> ps(N); set st; i64 one = 0; for (int i = 0; i < N; i++) { auto v = A[i]; if (v == 1) { one ++; continue; } for (auto p : primes) { if (p * p > v) break; if (v % p == 0) { while (v % p == 0) { v /= p; } ps[i].push_back(p); st.insert(p); } } if (v > 1) { ps[i].push_back(v); st.insert(v); } } int m = st.size(); vector a(st.begin(), st.end()); map ia; ranges::sort(a); for (int i = 0; i < m; i++) { ia[a[i]] = i; } atcoder::dsu ds(m); for (int i = 0; i < N; i++) { for (int j = 0; j < ps[i].size(); j++) { ds.merge(ia[ps[i][0]], ia[ps[i][j]]); } } vector b; for (int i = 0; i < m; i++) { if (ds.leader(i) == i) { b.push_back(a[i]); } } ranges::sort(b); if (b.size() == 0) { cout << one * 2 << endl; return 0; } i64 y = b.size(); i64 z = b[0]; i64 ans = INF; ans = min(ans, one * 2 + 2 + (y - 1) * z); ans = min(ans, (one + y) * 2); ans = min(ans, (one + y - 1) * z); cout << ans << endl; }