#include using namespace std; #include using namespace atcoder; const int M = 100000; int main(){ // cerr << "HI\n"; vector> L(M + 1); for(int i = 1; i < M + 1; i++){ int x = i; while(x < M){ L[x].push_back(i); x += i; } } // cerr << "HI\n"; int N; cin >> N; vector A(N); for(int i = 0; i < N; i++){ cin >> A[i]; } long long ans = 0; unordered_set S; for(int i = 0; i < N; i++){ if(S.count(A[i]) == 1){ ans += A[i]; }else{ S.insert(A[i]); } } A.clear(); for(long long x: S){ A.push_back(x); } N = (int)A.size(); vector>> D(M + 1); vector> Es; for(int i = 0; i < N; i++){ for(int p:L[A[i]]){ // cerr << i << "\n"; D[p].push_back({A[i], i}); } } for(int i = 1; i < M + 1; i++){ vector> &L = D[i]; if(L.size() > 1){ long long best = 1000000; int best_ind = -1; for(int j = 0; j < L.size(); j++){ if(best > L[j].first){ best = L[j].first; best_ind = j; } } for(int j = 0; j < L.size(); j++){ if(j != best_ind){ long long cost = L[best_ind].first * L[j].first / i; //cerr << L[best_ind].second << " " << L[j].second << " " << cost << "\n"; Es.push_back({cost, L[best_ind].second, L[j].second}); } } } } sort(Es.begin(), Es.end()); dsu d(N); for(auto cost_i_j : Es){ long long cost = get<0>(cost_i_j); int i = get<1>(cost_i_j); int j = get<2>(cost_i_j); if(!d.same(i, j)){ d.merge(i, j); ans += cost; } } cout << ans << "\n"; }