class UnionFindVerSize(): def __init__(self, N): self._parent = [n for n in range(0, N)] self._size = [1] * N self.group = N def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) stack = [x] while self._parent[stack[-1]]!=stack[-1]: stack.append(self._parent[stack[-1]]) for v in stack: self._parent[v] = stack[-1] return self._parent[x] def unite(self, x, y): gx = self.find_root(x) gy = self.find_root(y) if gx == gy: return self.group -= 1 if self._size[gx] < self._size[gy]: self._parent[gx] = gy self._size[gy] += self._size[gx] else: self._parent[gy] = gx self._size[gx] += self._size[gy] def get_size(self, x): return self._size[self.find_root(x)] def is_same_group(self, x, y): return self.find_root(x) == self.find_root(y) import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) M = 5 * 10**4 N = int(input()) A = li() res = 0 cnt = [0] * (M+1) for a in A: cnt[a] += 1 val_to_idx = [-1] * (M+1) B = [] for i in range(1,M+1): if cnt[i]: val_to_idx[i] = len(B) B.append(i) res += (cnt[i]-1) * i cnt[i] = 1 n = len(B) edge = [] for val in range(1,M+1): mini = M+1 for i in range(val,M+1,val): if cnt[i]: mini = i break if mini == M+1: continue for i in range(val,M+1,val): if cnt[i] and i!=mini: u = val_to_idx[mini] v = val_to_idx[i] edge.append((mini*i//val,u,v)) edge.sort(key=lambda e:e[0]) uf = UnionFindVerSize(n) for c,u,v in edge: if not uf.is_same_group(u,v): uf.unite(u,v) res += c print(res)