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. int[] m = new int[1000001]; m[0] = 0; m[1] = 1; for(int i=2; i <= 1000*1000; i++) { if (m[i] == 0) m[i] = i + 1; // break in i pieces, then eat each for(int k = 2*i; k <= 1000*1000; k+= i) { int poss = 1 + m[i] * (k/i); // break K into X even lots of i pieces each, then recurse if (m[k] < poss) m[k] = poss; } } Dictionary mm = new Dictionary(); mm[0] = 0; mm[1] = 1; for(int i=2; i <= 1000*1000; i++) { foreach(long b in a){ if (b > i && b % i == 0) { long poss = 1 + m[i] * (b/i); // break b into X even lots of i pieces each, then recurse if (!mm.ContainsKey(b) || mm[b] < poss) mm[b] = poss; } } } long ret = 0; foreach(long b in a){ ret += mm.ContainsKey(b) ? mm[b] : b+1; } return ret; } 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); } }