#include #include using namespace std; using isize = size_t; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = long double; using p2 = pair; using el = tuple; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) res *= t; t *= t; n >>= 1; } return res; } void _main() { i64 n; cin >> n; vector> prime(2000000); for (i64 i = 2; i < prime.size(); i++) { if (!prime[i].empty()) continue; prime[i] = {i}; for (i64 j = i * 2; j < prime.size(); j += i) { prime[j].push_back(i); } } vector a(n); vector edge; i64 sum = 0; for (i64 i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) continue; i64 x = a[i]; for (i64 p : prime[a[i]]) { i64 s = 0; while (x % p == 0) x /= p, s += p; if (s > 0) { edge.push_back({-s, i, p + n}); sum += s; } } } sort(edge.begin(), edge.end()); atcoder::dsu uf(n + prime.size()); for (auto [w, a, b] : edge) { if (!uf.same(a, b)) { uf.merge(a, b); sum += w; } } cout << sum << "\n"; }