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 getPrimes(max) { var sieve = [], i, j, primes = []; for (i = 2; i <= max; ++i) { if (!sieve[i]) { // i has not been marked -- it is prime primes.push(i); for (j = i << 1; j <= max; j += i) { sieve[j] = true; } } } return primes; } var primes = getPrimes(1000000); function longestSequence(a) { let arraySums = a.map(function(a){ if(a === 1){return 1;} let sum = a; while(a % 2 === 0){ a = a / 2; sum+=a; } while(a !== 1){ let ind = primes.indexOf(a); if(ind > -1){ a = a / primes[ind]; sum+=a; } else{ loop: for(let i=1;i