class UnionFind(): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N = int(input()) A = list(map(int, input().split())) M = 10 ** 5 + 5 def kruskal(edge): v = 0 edge.sort() U = UnionFind(M) for cost, i, j in edge: if U.is_same(i, j): continue U.union(i, j) v += cost return v D = [0] * M ans = 0 edge = [] for a in A: if D[a]: ans += a else: D[a] = 1 from math import gcd def lcm(a, b): return a * b // gcd(a, b) for i in range(1, M): mi = -1 for j in range(i, M, i): if not D[j]: continue if mi == -1: mi = j else: edge.append((lcm(mi, j), mi, j)) ans += kruskal(edge) print(ans)