import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 class UnionFind: def __init__(self, n): self.state = [-1]*n self.size_table = [1]*n self.cnt = n def root(self, u): stack = [] while self.state[u] >= 0: stack.append(u) u = self.state[u] for v in stack: self.state[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False du = -self.state[u] dv = -self.state[v] if du < dv: u, v = v, u if du == dv: self.state[u] -= 1 self.state[v] = u self.cnt -= 1 self.size_table[u] += self.size_table[v] return True def size(self, u): return self.size_table[self.root(u)] from heapq import * # m = 10 m=100001 n = II() aa = LI() idx = [[] for _ in range(m)] for i, a in enumerate(aa): idx[a].append(i) gtoa = [[] for _ in range(m)] for g in range(1, m)[::-1]: for h in range(g, m, g): if idx[h]: gtoa[g] += [(h, i) for i in idx[h]] # pDB(gtoa) hp = [] for g in range(1, m): if len(gtoa[g]) < 2: continue a, i = gtoa[g][0] b, j = gtoa[g][1] heappush(hp, (a*b//g, g, 0, 1)) uf = UnionFind(n) cnt = n-1 ans = 0 fin = set() while cnt: w, g, l, r = heappop(hp) _, i = gtoa[g][l] _, j = gtoa[g][r] if uf.merge(i, j): ans += w cnt -= 1 if (g, l, r+1) not in fin and r+1 < len(gtoa[g]): fin.add((g, l, r+1)) a, _ = gtoa[g][l] b, _ = gtoa[g][r+1] heappush(hp, (a*b//g, g, l, r+1)) if l+1 < r and (g, l+1, r) not in fin: fin.add((g, l+1, r)) a, _ = gtoa[g][l+1] b, _ = gtoa[g][r] heappush(hp, (a*b//g, g, l+1, r)) print(ans)