process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// var mem = {} function longestSequence(a) { // Return the length of the longest possible sequence of moves. let sum = 0 for (let i = 0; i < a.length; i++) { sum += recursion(a[i]) } return sum } function findDivisors(num) { const divisors = [] for (let i = 2; i <= num/i; i++) { if (num % i === 0) { divisors.push(i) divisors.push(num / i) } } return divisors } function recursion(size) { if (mem[size]) return mem[size] if (size === 1) { mem[size] = size return mem[size] } const divisors = findDivisors(size) if (divisors.length === 0) { mem[size] = size + 1 return mem[size] } let mostMoves = 0 for (let i = 0; i < divisors.length; i++) { const newSize = divisors[i] const blocks = size / newSize const moves = recursion(newSize) * blocks + 1 mostMoves = Math.max(moves, mostMoves) } mem[size] = mostMoves return mem[size] } function main() { var n = parseInt(readLine()); a = readLine().split(' '); a = a.map(Number); var result = longestSequence(a); process.stdout.write("" + result + "\n"); }