#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5005;
long long par[2 * MAXN], dist[2 * MAXN], bit[MAXN], n, tot[2 * MAXN],
    w[2 * MAXN], ans[2 * MAXN];
vector<long long> adj[2 * MAXN];
void update(long long now) {
  for (long long i = now; i <= 5000; i += (i & (-i))) bit[i]++;
}
long long query(long long now) {
  long long ret = 0;
  for (long long i = now; i > 0; i -= (i & (-i))) ret += bit[i];
  return ret;
}
void build() {
  vector<long long> V;
  dist[1] = 1;
  n = 5000;
  for (long long i = 2; i <= 5000; i++) {
    V.clear();
    long long tmp = i;
    for (long long j = 2; j * j <= tmp; j++) {
      if (tmp % j != 0) continue;
      long long pangkat = 0;
      while (tmp % j == 0) {
        pangkat++;
        tmp /= j;
      }
      for (long long k = 0; k < pangkat; k++) V.push_back(j);
    }
    if (tmp != 1) V.push_back(tmp);
    long long que = query(V.back() - 1);
    dist[i] = que + V.size();
    long long last = i - 1;
    while (dist[last] <= que) {
      que -= dist[last];
      last = par[last];
    }
    if (que == 0)
      par[i] = last;
    else {
      n++;
      par[i] = n;
      par[n] = par[last];
      par[last] = n;
      dist[n] = dist[last] - que;
      dist[last] = que;
    }
    for (auto isi : V) update(isi);
  }
  for (long long i = 2; i <= n; i++) {
    adj[par[i]].push_back(i);
  }
}
void dfs(long long now) {
  tot[now] = w[now];
  for (auto nxt : adj[now]) {
    dfs(nxt);
    tot[now] += tot[nxt];
    ans[now] += (tot[nxt] * dist[nxt]);
    ans[now] += ans[nxt];
  }
}
void dfs2(long long now) {
  for (auto nxt : adj[now]) {
    ans[nxt] += (ans[now] - (ans[nxt] + tot[nxt] * dist[nxt]));
    ans[nxt] += (dist[nxt] * (tot[1] - tot[nxt]));
    dfs2(nxt);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  build();
  long long x, a;
  cin >> x;
  for (long long i = 1; i <= x; i++) {
    cin >> a;
    if (a == 0) a = 1;
    w[a]++;
  }
  dfs(1);
  dfs2(1);
  long long jwb = 1e18;
  for (long long i = 1; i <= n; i++) jwb = min(jwb, ans[i]);
  cout << jwb << '\n';
  return 0;
}
