#include using namespace std; #define fi first #define se second #define pb push_back using vi = vector ; using ll = long long; using pii = pair ; //~ const ll mod = 998244353; const ll mod = 1e9 + 7; ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a; for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; } const int N = 1e5 + 11; vi divs[N]; vi muls[N]; int a[N]; int p[N]; int find(int x) { if(p[x] == x) return x; return p[x] = find(p[x]); } struct edge { int u, v; ll w; bool operator <(const edge &e) const { return w < e.w; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } int main() { ios :: sync_with_stdio(false); int n, m; cin >> n; ll ans = 0; for(int i = 1; i <= n; i ++) { int x; cin >> x; if(a[x]) ans += x; a[x] = 1; } for(int i = 1; i < N; i ++) for(int j = i; j < N; j += i) { divs[j].pb(i); if(a[j]) muls[i].pb(j); } for(int i = 1; i < N; i ++) sort(muls[i].begin(), muls[i].end()); vector edges; for(int i = 1; i < N; i ++) if(a[i]) { for(int x : divs[i]) { if(muls[x].size()) edges.pb({i, muls[x][0], lcm(i, muls[x][0])}); } } sort(edges.begin(), edges.end()); iota(p, p + N, 0); for(auto e : edges) { //~ cout << e.u << ' ' << e.v << ' ' << e.w << '\n'; int u = e.u, v = e.v; u = find(u); v = find(v); if(u != v) { ans += e.w; p[u] = v; } } cout << ans << '\n'; }