import heapq def aa(m): c=[] while m!=uf[m]: c.append(m) m=uf[m] for i in c: uf[i]=m return m n=int(input()) a=list(map(int,input().split())) if min(a)==1: ans=-1 for i in a: ans+=i print(ans) exit() x=[0]*(10**5+1) for i in a: x[i]+=1 v=[];ans=0 c=[[] for i in range(len(x))] d=[1<<60]*len(x) f=[0]*len(x) uf=[i for i in range(len(x))] for i in range(len(x)): if x[i]: ans+=(x[i]-1)*i for j in range(1,int(i**0.5)+1): if i%j==0: heapq.heappush(c[j],(i//j,i)) if j!=i//j: heapq.heappush(c[i//j],(j,i)) for i in range(len(x)): if len(c[i])>=2: q,w=heapq.heappop(c[i]) d[i]=q*i;f[i]=w q,w=heapq.heappop(c[i]) heapq.heappush(v,(d[i]*q,i,w)) while v: q,w,e=heapq.heappop(v) if aa(e)==aa(f[w]): continue ans+=q uf[aa(e)]=aa(f[w]) if c[w]: a,b=heapq.heappop(c[w]) heapq.heappush(v,(d[w]*a,w,b)) print(ans)