#include #include using namespace std; int main() { int N; cin >> N; vector A(N); for (int &a : A) cin >> a; long ans = 0; int M = *max_element(A.begin(), A.end()); vector V(M + 1); for (int a : A) { if (V[a]) ans += a; V[a] = 1; } vector> E; for (int i = 1; i <= M; i++) { for (int j = i; j <= M; j += i) { if (V[j]) { for (int k = j + i; k <= M; k += i) if (V[k]) E.emplace_back(j, k); break; } } } sort(E.begin(), E.end(), [&](auto a, auto b) { return lcm((long)a.first, a.second) < lcm((long)b.first, b.second); }); atcoder::dsu D(M + 1); for (auto &[a, b] : E) { if (!D.same(a, b)) { D.merge(a, b); ans += lcm((long)a, b); } } cout << ans << endl; }