class unionFind: def __init__(self,N): self.N=N self.parent=[-1 for i in range(N)] self.size=[1 for i in range(N)] def find(self,x): path=[x] while self.parent[path[-1]]!=-1: path.append(self.parent[path[-1]]) for i in path[:-1]: self.parent[i]=path[-1] return path[-1] def unite(self,x,y): roots=sorted([self.find(x),self.find(y)],key=lambda _:self.parent[_]) if roots[0]!=roots[1]: self.parent[roots[0]]=roots[1] self.size[roots[1]]+=self.size[roots[0]] def gcd(a,b): return gcd(a%b,b%a) if min(a,b)*(a-b) else max(a,b) def lcm(a,b): return a*b//gcd(a,b) def divisors(n): ans=[] for i in range(1,n+1): if n%i==0: ans.append(i) if i**2>n: break k=len(ans) for i in range(k-1,-1,-1): if n//ans[i]>ans[k-1]: ans.append(n//ans[i]) return ans N=int(input()) A=list(map(int,input().split())) M=max(A) dp=[[] for i in range(M)] for i in range(N): for j in divisors(A[i]): dp[j-1].append(i) cand=[] for i in range(M): dp[i]=sorted(dp[i],key=lambda x:A[x]) for j in dp[i][1:]: cand.append([dp[i][0],j]) cand=sorted(cand,key=lambda x:lcm(A[x[0]],A[x[1]])) U=unionFind(N) ans=0 for i in cand: if U.find(i[0])!=U.find(i[1]): U.unite(i[0],i[1]) ans+=lcm(A[i[0]],A[i[1]]) print(ans)