import math.sqrt import math.floor import collection.mutable.Queue object Solution { def divisors(n: Long): Array[Long] = { var divs: Queue[Long] = new Queue val sq = floor(sqrt(n)) var i = 2 divs += n while (i <= sq) { if (n % i == 0) { divs += i if (i != n / i) divs += n / i } i += 1 } return divs.toArray } def max(ar: Array[Long]): Long = { var m = Long.MinValue var i = 0 while (i < ar.length) { if (ar(i) > m) m = ar(i) i += 1 } m } def divide(n: Long, nops: Long, divs: Array[Long]): Long = { if (n == 1) return nops var ds: Queue[Long] = new Queue var i = 0 while (i < divs.length) { val d = divs(i) ds += divide(n / d, nops * d + d, divs.filter(x => n / d % x == 0)) i += 1 } ds.max } def longestSequence(a: Array[Long]): Long = { var sum: Long = 0 var i = 0 while (i < a.length) { sum += divide(a(i), 0, divisors(a(i))) + 1 i += 1 } 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) } }