/** * Created by Aminul on 12/15/2017. */ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.HashMap; import java.util.InputMismatchException; public class Breaking_Sticks_2 { public static void main(String[] args) throws Exception { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(System.out); 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); pw.println(result); pw.close(); } static long dp[]; static HashMap map = new HashMap<>(); static boolean isPrime(long x){ if(x <= 1_000_000) return dp[(int)x] == x+1; return BigInteger.valueOf(x).isProbablePrime(10); } static long get(long x){ long max = x+1; if(x == 1) max = 1; if(x <= 1_000_000) return dp[(int)x]; if(map.containsKey(x)) return map.get(x); if(BigInteger.valueOf(x).isProbablePrime(10)) return max; long sqrt = (int) Math.sqrt(x); for(long i = sqrt; i >= 2; i--){ if(x % i == 0){ long temp = 0; if(isPrime(i) || isPrime(x/i)){ temp = Math.max(get(i)*(x/i), get(x / i)*i) +1 ; max = Math.max(max, temp); break; } } } if(x > 1_000_000) map.put(x, max); return max; } static long longestSequence(long[] a) { dp = new long[(int)1e6+50]; dp[1] = 1; for(int i = 1; i <= 1_000_000; i++){ for(int j = 2; i*j <= 1_000_000; j++){ dp[i*j] = Math.max(dp[i*j], dp[i]*j+1); } } long ans = 0; for(long i : a){ ans += get(i); } return ans; } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; static final int ints[] = new int[128]; public FastReader(InputStream is) { for (int i = '0'; i <= '9'; i++) ints[i] = i - '0'; this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + ints[b]; } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + ints[b]; } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } /*private char buff[] = new char[1005]; public char[] nextCharArray(){ int b = skip(), p = 0; while(!(isSpaceChar(b))){ buff[p++] = (char)b; b = readByte(); } return Arrays.copyOf(buff, p); }*/ } }