#include #include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll MX = 200'010; void solve() { ll n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; ll min_pf = MX; vector has(MX + 10, vector()); rep(i, n) { ll rem = a[i]; for (ll j = 2; rem > 1 && j * j <= rem; j++) { if (rem % j == 0) { has[j].push_back(i); min_pf = min(min_pf, j); } while (rem % j == 0) rem /= j; } if (rem > 1) { has[rem].push_back(i); min_pf = min(min_pf, rem); } } atcoder::dsu dsu(n); rep(j, MX) { if (has[j].empty()) continue; ll i1 = has[j][0]; for (const auto i2 : has[j]) { if (i1 == i2 || dsu.same(i1, i2)) continue; dsu.merge(i1, i2); } } ll sz = dsu.groups().size(); ll ans = min(sz * 2, (sz - 1) * min_pf); cout << ans << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }