import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) mod=998244353 # エラトステネスの篩を用いた素因数分解・約数列挙 MAX=5*10**5+10 # 使いたい最大値を指定 # Sieve[i]で、iの最も小さい約数を返す。 Sieve=[i for i in range(MAX)] for i in range(2,MAX): if Sieve[i]!=i: continue for j in range(i,MAX,i): if Sieve[j]==j: Sieve[j]=i # 素因数分解 def fact(x): D=dict() while x!=1: k=Sieve[x] if k in D: D[k]+=1 else: D[k]=1 x//=k return D # 約数列挙 def faclist(x): LIST=[1] while x!=1: k=Sieve[x] count=0 while x%k==0: count+=1 x//=k LIST2=[] for l in LIST: for i in range(1,count+1): LIST2.append(l*k**i) LIST+=LIST2 return LIST LIST=[] for a in A: LIST+=fact(a) LIST=sorted(set(LIST)) D={LIST[i]:i for i in range(len(LIST))} E=[[] for i in range(N+len(LIST))] n=N+len(LIST) # UnionFind Group = [i for i in range(n)] # グループ分け Nodes = [1]*(n) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for i in range(N): a=A[i] for u in fact(a): Union(i,D[u]+N) #print([find(i) for i in range(n)]) k=LIST[0] c=0 for i in range(n): if find(i)==i: c+=1 ANS=k*(c-1) ANS2=2*c print(min(ANS,ANS2))