using System; using System.Collections.Generic; namespace Algorithms { class Program { static Dictionary stepsForPieceOfLength = new Dictionary(); static long longestSequence(long[] a) { long sum = 0; foreach (var piece in a) { sum += longest(piece); } return sum; } static long longest(long piece) { if (stepsForPieceOfLength.ContainsKey(piece)) { return stepsForPieceOfLength[piece]; } long max = piece + 1; long parts = 2; long alreadyTried = piece / 2; while (parts <= alreadyTried) { while (piece % parts != 0 && parts <= alreadyTried) { alreadyTried = piece / parts; parts++; } if (parts > alreadyTried) { break; } var times = 1; while (piece % (parts * times) == 0 && piece > parts * times) { var partLength = piece / (parts * times); max = exploreProblemSpace(max, parts * times, partLength); alreadyTried = partLength; times++; } parts++; } stepsForPieceOfLength[piece] = max; return max; } private static long exploreProblemSpace(long max, long parts, long partLength) { if (!stepsForPieceOfLength.ContainsKey(partLength)) { stepsForPieceOfLength[partLength] = longest(partLength); } var stepsForPart = parts * stepsForPieceOfLength[partLength] + 1; if (stepsForPart > max) { max = stepsForPart; } if (!stepsForPieceOfLength.ContainsKey(parts)) { stepsForPieceOfLength[parts] = longest(parts); } var stepsForPartTheOtherWayAround = partLength * stepsForPieceOfLength[parts] + 1; if (stepsForPartTheOtherWayAround > max) { max = stepsForPartTheOtherWayAround; } return max; } static void Main(String[] args) { stepsForPieceOfLength[1] = 1; stepsForPieceOfLength[2] = 3; 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); } } }