#include <bits/stdc++.h>
#pragma GCC optimze("Ofast")
using namespace std;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
const long long infi = 0x3f3f3f3f;
const long long mod = 1000000007;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
long long n, ans = infl;
vector<long long> a, per;
set<long long> used;
void f() {
  for (long long x : used) {
    long long cnt = 0;
    for (long long i = 0; i <= n - 1; i++) {
      long long y = a[i] % x;
      if (a[i] >= x)
        cnt += min(y, x - y);
      else
        cnt += x - y;
    }
    ans = min(ans, cnt);
  }
}
void solve() {
  cin >> n;
  a.resize(n);
  for (long long i = 0; i <= n - 1; i++) cin >> a[i], per.push_back(i);
  shuffle(per.begin(), per.end(), mt);
  for (long long j = 0; j < min(20ll, n); j++) {
    long long i = per[j];
    for (long long y = a[i] - 1; y <= a[i] + 1; y++) {
      long long x = y;
      for (long long t = 2; t * t <= x; t++) {
        if (x % t) continue;
        used.insert(t);
        while (x % t == 0) x /= t;
      }
      if (x > 1) used.insert(x);
    }
  }
  f();
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  long long t = 1;
  while (t--) solve();
  return 0;
}
long long norm(long long a) {
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
  return a;
}
long long powm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long divide(long long a, long long b) {
  return (a % mod) * powm(b, mod - 2) % mod;
}
