cache = {} def sieve(n): if n <= 2: return [] sieve = list(range(3, n, 2)) top = len(sieve) for si in sieve: if si: bottom = (si*si - 3) // 2 if bottom >= top: break sieve[bottom::si] = [0] * - ((bottom - top) // si) return [2] + [el for el in sieve if el] k_max = 10000000 k_list = sieve(k_max) def get_moves(n): if n not in cache: if n == 1: cache[n] = 0 return cache[n] for i in k_list: if n % i == 0: moves = int(n / i) cache[n] = moves + get_moves(moves) return cache[n] n_lim = int(n ** 0.5) for i in range(k_max+1, n_lim, 2): if n % i == 0: moves = int(n / i) cache[n] = moves + get_moves(moves) return cache[n] cache[n] = 1 return cache[n] def longestSequence(a): total_moves = 0 a = sorted(a) for i in a: total_moves = total_moves + i + get_moves(i) return total_moves if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = longestSequence(a) print(result)