import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def Find_Root(self, x): if self.root[x] < 0: return x else: self.root[x] = self.Find_Root(self.root[x]) return self.root[x] def Unite(self, x, y): x = self.Find_Root(x) y = self.Find_Root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def SameQuery(self, x, y): return self.Find_Root(x) == self.Find_Root(y) def Count(self, x): return -self.root[self.Find_Root(x)] mx = max(a) uf = UnionFind(mx) table = [-1] * (mx + 1) for i in range(N): table[a[i]] = i res = 0 for i in range(mx, 0, -1): c = (table[i] != -1) mn = mx t = 0 if table[i] != -1: mn = i t = i for j in range(i + i, mx + 1, i): if uf.SameQuery(i, j) or table[j] == -1: continue uf.Unite(i, j) c += 1 t += j mn = min(mn, j) #print(res, i, j) if c > 1: res += (t - mn) * mn // i #print(res, t, mn) for i in range(N): if table[a[i]] != i: res += a[i] print(res)