using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long longestSequence(long[] a) { // Return the length of the longest possible sequence of moves. Dictionary knownCounters = new Dictionary(); knownCounters.Add(1,1); long total = 0; for (int i = 0; i < a.Length; ++i) { long num = a[i]; if (knownCounters.ContainsKey(num)) total += knownCounters[num]; else { long res = GetMaxActions(num, knownCounters); knownCounters[num] = res; total += res; } } return total; } private static long GetMaxActions(long num, Dictionary knownCounters) { if (num == 1) return 1; long res = 0; long d = 2; long startNum = num; long startIdx = 2; while (startNum > 1) { while (startNum % d == 0) { if (startIdx < d) startIdx = d; startNum /= d; } d++; if (d * d > startNum && startNum > 1) { startIdx = startNum; break; } } if (startIdx != num) { long tmp = num / startIdx; res += 1; if (knownCounters.ContainsKey(tmp)) res += startIdx * knownCounters[tmp]; else { var maxActions = GetMaxActions(tmp, knownCounters); res += startIdx * maxActions; knownCounters[tmp] = maxActions; } } else res = num + 1; return res; } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] a_temp = Console.ReadLine().Split(' '); long[] a = Array.ConvertAll(a_temp,Int64.Parse); long result = longestSequence(a); Console.WriteLine(result); } }