import java.util.*; public class Solution { //static ExecutorService executor = Executors.newCachedThreadPool(); static class CacheCounter { int n = 0; int hit = 0; void hit(){ hit++; n++; } void miss(){ n++; } double hitRatio(){ return (((double) hit)/n); } } //static CacheCounter lvl1_cache_counter = new CacheCounter(); static CacheCounter lvl0_cache_counter = new CacheCounter(); static CacheCounter main_cache_counter = new CacheCounter(); static SortedMap> div_cache_0 = new TreeMap>(); //static Map> div_cache_1 = new HashMap>(); static Map cached = new HashMap(); static { cached.put(1L, 1L); } static List getDivisors1(long a) { /*if(div_cache_1.containsKey(a)) { lvl1_cache_counter.hit(); return div_cache_1.get(a); } lvl1_cache_counter.miss();*/ int square_root = (int) Math.sqrt(a) + 1; Long l = null; SortedMap> view = (square_root > 4) ? div_cache_0.tailMap(a) : null; boolean use_cache = false; if((view != null && !view.isEmpty())){ Iterator it = view.keySet().iterator(); while(it.hasNext() && !use_cache) { l = it.next(); if(l % a == 0) { use_cache = true; } } } List divisores = new ArrayList(); List tmp_list = new ArrayList<>(); if(use_cache) { List cache_list = div_cache_0.get(l.longValue()); int i = 0; while(i < cache_list.size() && cache_list.get(i) < square_root ) { //System.out.printf("###### %d - %d - %d\n", a, square_root, i); long v = cache_list.get(i++); if(a % v == 0) { divisores.add(v); tmp_list.add(v); if(v*v != a && a/v != a ) divisores.add(a/v); } } lvl0_cache_counter.hit(); div_cache_0.put(a, tmp_list); //div_cache_1.put(a, divisores); return divisores; }//else{ lvl0_cache_counter.miss(); div_cache_0.put(a, tmp_list); //} divisores.add(1L); tmp_list.add(1L); //System.out.printf("# %d - %d\n", a, square_root); for (int i = 2; i < square_root; i++) { //it_sq++; //System.out.printf("## %d - %d", a, i); if( a % i == 0 ){ if(i*i != a){ divisores.add(a/i); //System.out.printf(" -> %d ", a/i); } divisores.add((long)i); tmp_list.add((long)i); //if(update_cache) //System.out.printf(" --> %d ", i); } //System.out.printf(" \n"); } //div_cache_1.put(a, divisores); //Collections.sort(divisores, Collections.reverseOrder()); return divisores; } static long computeCost(long a, List divisores) { long max = 0; for(Long d : divisores){ long chunk_size = d; long n_chunks = a/d; //it++; long counter = 1 + n_chunks*split(chunk_size); //System.out.printf("%d length: %d ChunkSize: %d NChunks: %d ---> %d #", d, length, chunk_size, n_chunks, counter); if(counter > max){ max = counter; //max_changes++; } } return max; } static long split(long a){ if(cached.containsKey(a)){ main_cache_counter.hit(); return cached.get(a); } main_cache_counter.miss(); List divisores = getDivisors1(a); /*List good = Solution2.getDivisors(a); if( good.size() != divisores.size() || !(new HashSet(good)).equals((new HashSet(divisores)))) { System.err.println("############ "+ a +" ################"); System.err.println(Arrays.toString(good.toArray())); System.err.println(Arrays.toString(divisores.toArray())); System.err.println("############ "+ a +" ################"); throw new Error(); }*/ //System.out.printf("#### %d --> %s - %s \n", a, Arrays.toString(divisores.toArray()), Arrays.toString(exp_cache.toArray())); //System.out.println("Divisores: " + Arrays.toString(divisores.toArray())); long max = computeCost(a, divisores); cached.put(a, max); return max; } /*static long longestSequenceMT(long[] a) throws InterruptedException { final AtomicLong c = new AtomicLong(0); for(final long s : a){ executor.execute(() -> { long r = split(s); c.addAndGet(r); }); } executor.shutdown(); executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); return c.get(); }*/ static long longestSequence(long[] a) throws InterruptedException { // Return the length of the longest possible sequence of moves. long c = 0; Arrays.sort(a); for(int i = a.length - 1; i >= 0 ; i--){ long r = split(a[i]); c += r; //System.out.printf("Result: %d -> %d\n", s,c); } return c; } public static void main(String[] args) throws InterruptedException { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] a = new long[n]; for(int a_i = 0; a_i < n; a_i++){ a[a_i] = in.nextLong(); } long result = longestSequence(a); System.out.println(result); in.close(); } }