#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=998244353 import sys input=sys.stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): now = x tmpl = [] while self.parents[now] >= 0: tmpl.append(now) now = self.parents[now] for xx in tmpl: self.parents[xx] = now return now def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return x if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x return x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x):#O(n)かかる。全部求めたい場合は、all_group_membersを使う。 root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) maxa = 10 ** 5 + 1 n = int(input()) a = list(map(int,input().split())) l = [-1] * maxa uf = UnionFind(n) ans = 0 for i,aa in enumerate(a): if l[aa] == -1: l[aa] = i else: ans += aa ca = [[] for _ in range(maxa)] for i in range(1,maxa): for j in range(1,maxa): if i * j > maxa - 1: break if l[i * j] != -1: ca[i].append([i * j,l[i * j]]) edge = [] for i in range(1,maxa): for j in range(1,len(ca[i])): edge.append([ca[i][0][0] * ca[i][j][0] // i,ca[i][0][1],ca[i][j][1]]) edge.sort(key = operator.itemgetter(0)) for dis,i,j in edge: if uf.same(i,j): continue ans += dis uf.union(i,j) print(ans)