import math class UnionFind: def __init__(self, n): self.node = [-1 for _ in range(n)] def root(self, v): if self.node[v] < 0: return v st = [] while self.node[v] >= 0: st.append(v) v = self.node[v] for u in st: self.node[u] = v return v def size(self, v): v = self.root(v) return (- self.node[v]) def same(self, u, v): return self.root(u) == self.root(v) def unite(self, u, v): ru = self.root(u) rv = self.root(v) if ru == rv: return du = self.node[ru] dv = self.node[rv] if du <= dv: self.node[rv] = ru self.node[ru] += dv else: self.node[ru] = rv self.node[rv] += du INF = 1 << 60 n = int(input()) a = list(map(int, input().split())) grp = [[] for _ in range(100001)] for i in range(n): for x in range(1, int(math.sqrt(a[i])) + 1): if a[i] % x == 0: grp[x].append(i) if x != a[i] // x: grp[a[i] // x].append(i) edges = {} for x in range(1, 100001): if len(grp[x]) < 2: continue grp[x].sort(key=lambda i: - a[i]) u = grp[x].pop() for v in grp[x]: edges[u * n + v] = min(edges.get(u * n + v, INF), a[u] * a[v] // x) edges = sorted(list(edges.items()), key=lambda x: x[1]) uf = UnionFind(n) ans = 0 for e, w in edges: u, v = e // n, e % n if not uf.same(u, v): uf.unite(u, v) ans += w print(ans)