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 //////////////////// function longestSequence(a) { // Return the length of the longest possible sequence of moves. const primes = []; const composites = []; let moves = 0; for (const n of a) { let bars = 1; let barSize = n; while(barSize > 1) { const pieces = greatestPrimeFactor(barSize); //console.log(`gpm of ${barSize}: ${pieces}`); moves += bars; bars *= pieces; barSize /= pieces; } moves += n; } return moves; function greatestPrimeFactor(n) { const primeFactors = factors(n); //console.log(`all prime factors of ${n}: `, primeFactors); return Math.max.apply(null, primeFactors); } function factors(n) { for (let i = 2; i <= n/2; i++) { //console.log(i,n); if (n % i === 0 && isPrime(i)) { return [i].concat(factors(n / i)); } } return [n]; } function isPrime(n) { //console.log(`is ${n} prime?`); if (primes.includes(n)) return true; if (composites.includes(n)) return false; for (let i = 2; i <= n/2; i++) { if (n % i === 0){ composites.push(n); //console.log(`${n} is composite`); return false; } } primes.push(n); //console.log(`${n} is prime`); return true; } } function main() { var n = parseInt(readLine()); a = readLine().split(' '); a = a.map(Number); var result = longestSequence(a); process.stdout.write("" + result + "\n"); }