#!/bin/ruby require 'prime' @cache = { 1 => 0 } def largest_prime_divider(x) return @cache[x] if @cache[x] return 0 if x == 1 @cache[x] = Prime.prime_division(x).max_by(&:first).first end def longest_move(x) res = largest_prime_divider(x) return res + 1 if res == x || res == 0 1 + res * longest_move(x/res) end def longestSequence(a) # Return the length of the longest possible sequence of moves. a.inject(0) { |ac, x| ac + longest_move(x) } end n = gets.strip.to_i a = gets.strip a = a.split(' ').map(&:to_i) result = longestSequence(a) puts result