#!/bin/python3 import sys, math divisors = dict([(1, 1)]) lcs = dict([(1,1)]) def getDivisors(n): #yields all divisors of n but n for i in range(1, math.ceil((n/2)+1)): if n%i == 0: yield i def getEfficientDivisors(n): #yields all divisors of n but n yield 1 for i in range(2, math.ceil((math.sqrt(n))+1)): if n%i == 0: yield i yield int(n/i) def longestChocolateSequenceList(aa): result = [] for a in aa: result.append(longestChocolateSequence(a)) return result def longestChocolateSequence(a): if a == 1: return 1 if a == 2: return 3 else: candidates = [] if a in divisors: divs = divisors[a] else: divs = sorted(list(getEfficientDivisors(a))) divisors[a] = divs if len(divs) > 0: for divisor in divs: times = int(a/divisor) if divisor in lcs: tmp = lcs[divisor] else: tmp = longestChocolateSequence(divisor) lcs[divisor] = tmp candidates.append(times*tmp) rr = max(a+1, 1 +max(candidates)) lcs[a] = rr return(rr) else: lcs[a] = a+1 return(a+1) if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) if isinstance(a,list): result = longestChocolateSequenceList(a) else: result = longestChocolateSequence(a) print (sum(result))