#include <bits/stdc++.h>
using namespace std;
inline int Abs(int x) { return x < 0 ? -x : x; }
const int maxn = 5010;
int cnt[maxn], cnt1[maxn], T, n;
int vis[maxn], pri[maxn], Cnt;
int val[maxn], c[100100], v[maxn];
int main() {
  scanf("%d", &T);
  for (int x, i = 1; i <= T; i++)
    scanf("%d", &x), x = max(x, 1), cnt[x]++, cnt1[x]++, n = max(n, x);
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pri[++Cnt] = i;
    for (int j = 1; j <= Cnt && i * pri[j] <= n; j++) {
      vis[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
  long long ans = 0;
  for (int i = Cnt; i; i--) {
    for (int j = 1; j <= n; j++)
      if (cnt[j]) {
        int k = 0;
        for (int k1 = j; k1 >= pri[i]; k1 /= pri[i]) k += k1 / pri[i];
        val[j] = k;
        c[k] += cnt1[j];
      }
    c[0] += cnt1[0];
    int N = 0, J = 0;
    for (; J <= n; J++) {
      N += c[J];
      if (N * 2 >= T) break;
    }
    for (int j = 0; j <= n; j++) c[j] = 0;
    for (int j = 0; j <= n; j++)
      if (cnt[j]) {
        if (!v[j])
          ans += 1ll * Abs(val[j] - J) * cnt[j];
        else
          ans += 1ll * Abs(val[j] + J) * cnt[j];
      }
    for (int j = 1; j <= n; j++)
      if (cnt1[j] && val[j] != J) cnt1[0] += cnt1[j], cnt1[j] = 0, v[j] = 1;
  }
  printf("%lld\n", ans);
}
