#include using namespace std; #define ll long long #define endl "\n" #define str string #define yes cout << "YES" #define no cout << "NO" #define in cout << #define mll map #define fi first #define se second ll n,t=1,maxn=1e7,c[10000005],a[100005],pfs[100005]; vectorsnt; vector>lt; void sieve() { for (int i = 2; i <= maxn; i++) c[i] = 1; for (int i = 2; i <= sqrt(maxn); i++) { if (c[i]) { for (int j = i * i; j <= maxn; j += i) c[j] = 0; } } for (int i = 2; i <= maxn; i++) { if (c[i]) { snt.push_back(i); if (i <= sqrt(maxn)) { vectortemp; temp.push_back(1); ll last = 1; while (last <= maxn / i) { last *= i; temp.push_back(last); } lt.push_back(temp); } } } // cout << lt.size() << " " << snt.size(); } void read() { sieve(); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a+1,a+n+1); ll res = 1e18; for (int j = 0; j < lt.size(); j++) { ll cnt = 0; for (int i = 1; i <= n; i++) { ll pos = upper_bound(lt[j].begin(), lt[j].end(), a[i]) - lt[j].begin(); auto it = upper_bound(lt[j].begin(), lt[j].end(), a[i]); if (it == lt[j].end()) { cnt += a[i] - lt[j][pos-1]; continue; } ll lef = lt[j][pos-1], righ = lt[j][pos]; // if (snt[j] == 29) cout << i << " " << lef << " " << righ << endl; cnt += min(righ - a[i], a[i] - lef); } // if (cnt < res) cout << snt[j] << " " << cnt << endl; res = min(res, cnt); } for (int i = 1; i <= n; i++) pfs[i] = pfs[i-1] + a[i]; for (int i = lt.size(); i < snt.size(); i++) { ll temp = lower_bound(a+1,a+n+1,snt[i]) - a - 1; res = min(res, snt[i] * temp - pfs[temp] + pfs[n] - pfs[temp] - (n - temp) * snt[i]); } cout << res; } void solve() { while (t--) { } } int main() { // freopen(".INP", "r", stdin); // freopen(".OUT", "w", stdout); cin.tie(0)->sync_with_stdio(0); read(); solve(); return 0; }