#include using namespace std; #ifdef _RUTHEN #include "debug.hpp" #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template using V = vector; #include int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; V A(N); rep(i, N) cin >> A[i]; ll m = *min_element(A.begin(), A.end()); const int M = 100000; V cnt(M + 1, 0); rep(i, N) cnt[A[i]]++; V> G(M + 1); for (int i = 1; i <= M; i++) { for (int j = 2 * i; j <= M; j += i) { G[j].push_back(i); } } ll ans = 0; V B; for (int i = M; i >= 1; i--) { if (cnt[i] == 0) continue; ans += i * (cnt[i] - 1); int ok = 0; for (auto d : G[i]) { if (cnt[d] != 0) { ok = 1; break; } } if (ok) { ans += i; } else { B.push_back(i); } } show(B, ans); int N2 = B.size(); V>> es; rep(i, N2) { rep(j, i) { es.push_back({lcm(B[i], B[j]), {i, j}}); } } sort(es.begin(), es.end()); atcoder::dsu uf(N2); for (auto [cost, p] : es) { if (!uf.same(p.first, p.second)) { uf.merge(p.first, p.second); ans += cost; } } cout << ans << '\n'; return 0; }