class UnionFind: def __init__(self, n): self.node = [-1 for _ in range(n)] def size(self, v): v = self.root(v) return (- self.node[v]) 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 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[u] dv = self.node[v] if du <= dv: self.node[rv] = ru self.node[ru] += dv else: self.node[ru] = rv self.node[rv] += du n = int(input()) a = list(map(int, input().split())) vs = [] for v in range(n): vs.append((v, a[v])) vs.sort(key=lambda x: x[0]) m = max(a) par = {} edges = [] for v, c in vs: if par.get(c, None) is None: par[c] = v else: edges.append((par[c], v, c)) for x in range(1, m + 1): for y in range(x, m + 1, x): if par.get(y, None) is None: continue if par.get(x, None) is None: par[x] = par[y] if par[x] == par[y]: continue edges.append((par[x], par[y], a[par[x]] * a[par[y]] // x)) edges.sort(key=lambda x: x[2]) uf = UnionFind(n) ans = 0 for u, v, w in edges: if not uf.same(u, v): uf.unite(u, v) ans += w print(ans)