def gcd(a, b): while a != 0: b %= a if b == 0: return a a %= b return b class UnionFind(): def __init__(self,n): self.data = [-1 for i in range(n)] def find(self,x): stack = [] while self.data[x] >= 0: stack.append(x) x = self.data[x] while len(stack): y = stack.pop() self.data[y] = x return x def unite(self,x,y): x,y = self.find(x),self.find(y) if x == y: return if self.data[x] > self.data[y]: x,y = y,x self.data[x] += self.data[y] self.data[y] = x return def same(self,x,y): return self.find(x) == self.find(y) def size(self,x): return -self.data[self.find(x)] N = int(input()) A = list(map(int,input().split())) M = 100000 B = [0] * (M + 1) m = min(A) for a in A: B[a] += 1 ans = 0 for a in range(1,M + 1): if B[a] == 0: continue ans += a * (B[a] - 1) B[a] = 1 A = [] for a in range(1,M + 1): if B[a]: A.append(a) N = len(A) E = [] for i in range(1,M + 1): X = [] for j in range(1,M + 1): if i * j > M: break if B[i * j]: X.append(i * j) if len(X) == 0: continue x = X[0] for i in range(1,len(X)): l = (x * X[i]) // gcd(x,X[i]) E.append((l,x - 1,X[i] - 1)) E.sort() uf = UnionFind(M) for c,u,v in E: if uf.same(u,v): continue uf.unite(u,v) ans += c print(ans)