object Solution { def factorize(x: Long): List[Long] = { def foo(x: Long, a: Long): List[Long] = x % a match { case _ if a*a > x => List(x) case 0 => a :: foo(x/a, a) case _ => foo(x, a+1) } foo(x, 2L) } def longestSequence(a: Array[Long]): Long = { // Return the length of the longest possible sequence of moves. var stotal = 0L for(anum <- a) { var total = 1L if(anum == 1) { stotal += 1L } else { val pfactors = factorize(anum) // prime factors //println(pfactors) var num = 1L for(pf <- pfactors) { // println(pf) if(num ==1L) { total = pf } else if(pf > 1) total = (1 + total) * pf num += 1L } stotal += (total + 1L) } } return stotal } def main(args: Array[String]) { val sc = new java.util.Scanner (System.in); var n = sc.nextInt(); var a = new Array[Long](n); for(a_i <- 0 to n-1) { a(a_i) = sc.nextLong(); } val result = longestSequence(a); println(result) } }