#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; //using mint = modint998244353; #define rep(i,n) for (int i=0;i-1;i--) #define append push_back #define all(x) (x).begin(), (x).end() template using vec = vector; template using vvec = vec>; template using vvvec = vec>; using ll = long long; using pii = pair; using pll = pair; template bool chmin(T &a, T b){ if (a>b){ a = b; return true; } return false; } template bool chmax(T &a, T b){ if (a T sum(vec x){ T res=0; for (auto e:x){ res += e; } return res; } template void printv(vec x){ for (auto e:x){ cout<>= 1; } return res; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; cin>>N; vec cnt(1e6+1,0); int M = 1e6; rep(i,N){ int a; cin>>a; cnt[a]++; } ll res = 0; vec A; for (int i=1;i<=M;i++){ if (cnt[i] > 1){ res += i * (cnt[i]-1); cnt[i] = 1; } if (cnt[i]==0){continue;} A.append(i); for (int j=2*i;j<=M;j+=i){ if (cnt[j]!=0){ res += j * cnt[j]; cnt[j] = 0; } } } int n = A.size(); vec> Edge; rep(i,n){ rep(j,n){ if (i < j){ ll cost = lcm((ll)A[i],(ll)A[j]); Edge.append({cost,i,j}); } } } sort(all(Edge)); dsu uf(n); for (auto [c,u,v]:Edge){ if (!uf.same(u,v)){ res += c; uf.merge(u,v); } } cout<