import Foundation func longestSequence(of number: Int) -> Int { let primes = primeFactors(of: number) let needsExtraStep = number > 1 let initialValue = needsExtraStep ? 1 : 0 return primes.reduce(initialValue, +) } func primeFactors(of number: Int) -> [Int] { guard number >= 4 else { return [number] } let max = Int(sqrt(Double(number))) for divisor in 2...max { if number % divisor == 0 { var result = [number] result.append(contentsOf: primeFactors(of: number / divisor)) return result } } return [number] } _ = readLine() // ignoring the first line as we can get the number chocolates from the array let chocolates = readLine()!.components(separatedBy: " ").flatMap(Int.init) let result = chocolates.map(longestSequence).reduce(0, +) print(result)