#include #include using namespace std; using ll = long long; const ll MAX = 1e5; void solve() { ll N; cin >> N; vector cnt(MAX + 1); ll ans = 0; for (ll i = 0; i < N; i++) { ll x; cin >> x; if (cnt[x]) ans += x; else cnt[x] = 1; } vector> edge; for (ll g = 1; g <= MAX; g++) { pair prev; for (ll i = g, c = 1; i <= MAX; i += g, c++) { if (!cnt[i]) continue; if (prev.first == 0) { prev = {i, c}; continue; } edge.push_back({prev.first, i, prev.second * i}); } } ranges::sort(edge, {}, [](const auto& x) { return x[2]; }); atcoder::dsu uf(MAX + 1); for (auto [x, y, w] : edge) { if (uf.same(x, y)) continue; ans += w; uf.merge(x, y); } cout << ans << '\n'; } int main() { cin.tie(0)->sync_with_stdio(0); solve(); }