#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define PROFILE_START(i) clock_t start##i = clock() #define PROFILE_STOP(i) fprintf(stderr, "elapsed time (" #i ") = %f\n", double(clock() - start##i) / CLOCKS_PER_SEC) #ifndef M_PI #define M_PI 3.14159265358979323846 // pi #define M_1_PI 0.318309886183790671538 // 1/pi #define M_SQRT2 1.41421356237309504880 // sqrt(2) #endif typedef long long ll; typedef unsigned long long ull; typedef vector vi; typedef pair pii; typedef pair pll; #define fi first #define se second #define pb push_back #define eb emplace_back #define em emplace #define mp make_pair #define mt make_tuple inline vector eratosthenes(int n) { vector res(n + 1, true); res[0] = false; res[1] = false; if (n >= 4) { for (int j = 2 * 2; j <= n; j += 2) res[j] = false; } int root = (int)sqrt(n); for (int i = 3; i <= root; i += 2) { if (res[i]) { for (int j = i * i; j >= 0 && j <= n; j += i) res[j] = false; } } return move(res); } unordered_map gPP; bool isPrime(ll x) { auto it = gPP.find(x); if (it != gPP.end()) return it->second; int n = (int)sqrt(x); while (n >= 2) { if (x % n == 0) return gPP[x] = false; n--; } return gPP[x] = true; } #define MAXV 1000000 vector gP; unordered_map gM; ll solve(ll x) { if (x == 1) return 0 + 1; else if (x == 2) return 2 + 1; auto it = gM.find(x); if (it != gM.end()) return it->second; ll maxV = 0; ll a = (ll)sqrt(x); while (a > 1) { if (x % a == 0) { ll b = x / a; if (a == b) { if (gP[(int)a]) { maxV = max(maxV, solve(a) * b + 1); break; } } else { if (isPrime(b)) { maxV = max(maxV, solve(a) * b + 1); break; } else if (gP[(int)a]) { maxV = max(maxV, solve(b) * a + 1); break; } } } --a; } maxV = max(maxV, x + 1); return gM[x] = maxV; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector A(N); ll maxA = 0; for (int i = 0; i < N; i++) { cin >> A[i]; maxA = max(maxA, A[i]); } gP = eratosthenes((int)sqrt(maxA) + 1); ll ans = 0; for (int i = 0; i < N; i++) { ans += solve(A[i]); //cerr << ans << endl; } cout << ans << endl; return 0; }