// #pragma GCC optimize ("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target ("avx,avx2,fma") #include using std::cin, std::cout, std::cerr; using ll = long long; const int N = 1e6 + 1; int p[N]; int main() { std::iota(p, p + N, 0); for(int i = 2; i < N; i ++) if(p[i] == i) { for(int j = i * 2; j < N; j += i) { p[j] = p[j] == j ? i : p[j]; } } std::ios::sync_with_stdio(false); int n; cin >> n; std::vector> e; for(int i = 1; i <= n; i ++) { int x; cin >> x; while(x != 1) { int y = p[x], c = 0; while(x % y == 0) { x /= y; c += y; } e.push_back({c, i, n + y}); } } std::sort(e.rbegin(), e.rend()); std::vector fa(n + N + 1); std::iota(fa.begin(), fa.end(), 0); std::function root = [&](int x) { if(x == fa[x]) return x; return fa[x] = root(fa[x]); }; ll ans = 0; for(auto [c, u, v] : e) { int x = root(u), y = root(v); if(x == y) ans += c; else fa[x] = y; } cout << ans << '\n'; }