import util.control.Breaks._ object Solution { def getMovesStick(size: Long, pieces: Long, moves: Long): Long = { if (size == 1) { moves + pieces; } else { var div = size; for(i <- 2L until size){ if(size % i == 0){ div = i } } getMovesStick((size / div), div * pieces, moves + pieces); } } def longestSequence(a: Array[Long]): Long = { a.map(getMovesStick(_, 1, 0)).sum } 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) } }