#include using namespace std; #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define bit(n,i) ((n>>i)&1) #define all(x) x.begin(),x.end() #define int long long typedef long long ll; typedef pair pii; typedef double ld; typedef pair pdd; typedef pair pll; const ll maxn=1e6+5; const ll offset=2e5; const ll blk=317; const ll inf=1e9; const int base=350; const ll mod=998244353; int n; int a[maxn],b[maxn]; int par[maxn]; int cnt[maxn]; int Find(int u) { return par[u]<0?u:par[u]=Find(par[u]); } bool Union(int u,int v) { if ((u=Find(u))==(v=Find(v))) return false; if (par[u]> par[v]) swap(u,v); par[u]+=par[v]; par[v]=u; return true; } vector L; vector> Edge; int lcm(int a,int b) { return a * b / __gcd(a,b); } void sol() { cin >> n; for1(i,1,n) par[i]=-1; for1(i,1,n) { cin >> a[i]; cnt[a[i]]++; } sort(a+1,a+1+n); for1(i,1,n) { if (b[a[i]]) Union(b[a[i]],i); else b[a[i]]=i; } for1(i,1,1e5) { if(cnt[i] > 1) continue; L.clear(); for3(j,i,1e5,i) { if (b[j]) L.pb(j); } if (L.size()<2) continue; for1(j,1,L.size()-1) Edge.pb({lcm(L[0],L[j]),{L[0],L[j]}}); } sort(all(Edge)); int res=0; for(auto x:Edge) { if (Union(b[x.se.fi],b[x.se.se])) res+=x.fi; } cout << res<<'\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("paleta.inp","r",stdin); // freopen("paleta.out","w",stdout); int t=1;//cin >> t; while (t--) { sol(); } } /* 1 5 3 4 1 2 3 1 */