#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Edge { int from; int to; ll cost; Edge(int from = -1, int to = -1, ll cost = -1) { this->from = from; this->to = to; this->cost = cost; } bool operator>(const Edge &n) const { return cost > n.cost; } }; class UnionFind { public: vector _parent; vector _rank; vector _size; UnionFind(int n) { for (int i = 0; i < n; ++i) { _parent.push_back(i); _rank.push_back(0); _size.push_back(1); } } int find(int x) { if (_parent[x] == x) { return x; } else { return _parent[x] = find(_parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (_rank[x] < _rank[y]) { _parent[x] = y; _size[y] += _size[x]; } else { _parent[y] = x; _size[x] += _size[y]; if (_rank[x] == _rank[y]) ++_rank[x]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return _size[find(x)]; } }; int main() { int N; cin >> N; vector A(N); ll ans = 0; ll M = 0; vector counter(100010, 0); for (int i = 0; i < N; ++i) { cin >> A[i]; M = max(M, A[i]); counter[A[i]]++; } priority_queue , greater> pque; vector checked(M + 1, false); for (ll d = 1; d <= M; ++d) { if (counter[d] > 0) { ans += d * (counter[d] - 1); } ll min_x = -1; for (ll x = d; x <= M; x += d) { if (counter[x] == 0) continue; if (checked[d]) { pque.push(Edge(min_x, x, min_x * x / d)); } else { min_x = x; checked[d] = true; } } } UnionFind uf(100010); while (not pque.empty()) { Edge e = pque.top(); pque.pop(); if (uf.same(e.from, e.to)) continue; uf.unite(e.from, e.to); ans += e.cost; } cout << ans << endl; return 0; }