#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; constexpr int MX = 100010; VI d[MX]; } int main() { ios::sync_with_stdio(false); cin.tie(0); for(int i = 1; i < MX; i++) { for(int j = i; j < MX; j += i) { d[j].emplace_back(i); } } int n; cin >> n; VI a(n); vector>> vals(MX); rep(i, n) { cin >> a[i]; for(int x: d[a[i]]) { vals[x].emplace(a[i], i); } } ll ans = 0; dsu uf(n); while(true) { auto gs = uf.groups(); if (gs.size() == 1) break; vector

todo; for(const auto& g: gs) { for(int i: g) { for(int x: d[a[i]]) { vals[x].erase({a[i], i}); } } ll mn = 1002003004005006007; int i1 = -1, i2 = -1; for(int i: g) { for(int x: d[a[i]]) if (auto it = vals[x].begin(); it != vals[x].end()) { ll cost = ll(a[i] / x) * it->first; if (cost < mn) { mn = cost; i1 = i, i2 = it->second; } } } todo.emplace_back(i1, i2); for(int i: g) { for(int x: d[a[i]]) { vals[x].emplace(a[i], i); } } } for(auto [i, j]: todo) if (!uf.same(i, j)) { uf.merge(i, j); ans += lcm(a[i], a[j]); } } cout << ans << endl; }