#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } struct UnionFind { vector data; UnionFind(int size) : data(size, -1) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; const int N = 100000; using T = tuple; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector cnt(N+1); for(int i = 0; i < n; i++) { int a; cin >> a; cnt[a]++; } ll ans = 0; for(int i = 1; i <= N; i++) { if(cnt[i] > 0) ans += (cnt[i]-1)*i; } vector edges; for(int x = 1; x <= N; x++){ vector v; for(int i = 1; i*x <= N; i++){ if(cnt[i*x] > 0) v.push_back(i*x); } for(int i = 1; i < v.size(); i++){ ll w = (ll)v[0]*(ll)v[i]/x; edges.push_back(T(w, v[0], v[i])); } } sort(edges.begin(), edges.end()); UnionFind uf(N+1); for(auto [w, u, v]: edges){ if(!uf.findSet(u, v)){ uf.unionSet(u, v); ans += w; } } cout << ans << endl; }