#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector a(n); rep(i,0,n){ cin >> a[i]; } dsu uf(600000); int geta = 300000; vector> d(214159, vector(0)); vector pl(214159, false); for (int i=2; i<=211000; i++){ if (pl[i]) continue; for (int j=i; j<=211000; j+=i){ pl[j] = 1; d[j].push_back(i); } } vector used(300000); rep(i,0,n){ for (int p: d[a[i]]){ uf.merge(i, geta + p); } } ll onecnt = 0; rep(i,0,n){ if (a[i] == 1){ onecnt++; } } map mp; int minuse = 998244; rep(i,0,300000){ if (uf.size(geta + i) == 1) continue; if (mp.find(uf.leader(geta + i)) == mp.end()){ mp[uf.leader(geta + i)] = 998244; } chmin(mp[uf.leader(geta + i)], i); chmin(minuse, i); } ll ans = (ll)n * 2; if (uf.size(geta + 2) != 1){ chmin(ans, 2 * onecnt + 2 * ((ll)mp.size() - 1)); }else{ if (minuse == 998244){ chmin(ans, (ll)n * 2); }else{ chmin(ans, minuse * onecnt + minuse * ((ll)mp.size() - 1)); chmin(ans, 2 * onecnt + 2 * (ll)mp.size()); } } cout << ans << '\n'; }