#include using namespace std; #define ll long long struct DSU { vector Rank, Root, mn; DSU(int n) { Rank.resize(n + 1, 1); Root.resize(n + 1); iota(Root.begin(), Root.end(), 0); mn = Root; } int find(int Node) { return Root[Node] = (Node == Root[Node] ? Node : find(Root[Node])); } bool check(int a, int b) { return (find(a) == find(b)); } void merge(int a, int b) { a = find(a); b = find(b); mn[a] = mn[b] = min(a, b); if (check(a, b)) return; if (Rank[a] > Rank[b]) swap(a, b); Root[a] = b; Rank[b] += Rank[a]; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); const int N = 1e5 + 5; vector mx(N, 0); vector counter(N, 0); int n; cin >> n; for (int i = 0, x; i < n; ++i) { cin >> x; counter[x]++; } ll ans = 0; int mn = 1e9; for (int i = 1; i < N; ++i) { if (counter[i] == 0) { continue; } for (int j = i + i; j < N; j += i) { if (counter[j] > 0) { mx[j] = i; } } ans += 1ll * (counter[i] - 1) * i; if (mn == 1e9) { mn = i; } } assert(mn != 1e9); DSU dsu(N); for (int i = 1; i < N; ++i) { if (counter[i] != 0 && mx[i] != 0) { dsu.merge(i, mx[i]); ans += i; } } for (int i = 1; i < N; ++i) { if (counter[i] > 0 && dsu.find(i) == i && i != mn) { int x = dsu.mn[dsu.find(i)]; ans += 1ll * x * mn / __gcd(x, mn); } } cout << ans << '\n'; return 0; }