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. long totalSequence = 0; foreach (var i in a) { totalSequence += ComputeLongestSequence(i); } return totalSequence; } private static long ComputeLongestSequence(long a) { if (a == 1) return 1; IEnumerable lcfs = GetLcfs(a); long m = 1; long longestSequence = 1; foreach (var lcf in lcfs) { m = m * lcf; longestSequence += m; } return longestSequence; } private static IEnumerable GetLcfs(long a) { ICollection lcfs = new List(); long m = a; long n = 2; while (true) { if (m % n == 0) { lcfs.Add(n); if (m == n) break; m = m / n; //reset n n = 2; continue; } // get largest prime factor n = GetSmallestPrimeFactor(m); } return lcfs.OrderByDescending(x => x); } private static long GetSmallestPrimeFactor(long a) { long n = (long) Math.Ceiling(Math.Sqrt(a)); for (long i = 2; i < n; i++) { if (a % i == 0) return i; } return a; } static bool isValidLength(long a) { return a >= 1 && a <= Math.Pow(10, 12); } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); if (n < 1 || n > 100) return; string[] a_temp = Console.ReadLine().Split(' '); long[] a = Array.ConvertAll(a_temp,Int64.Parse); foreach (var i in a) { if (!isValidLength(i)) return; } long result = longestSequence(a); Console.WriteLine(result); } }