#include <bits/stdc++.h>
using namespace std;
const int inf = ~0u >> 2;
const long long INF = ~0ull >> 2;
long long read() {
  long long x;
  if (scanf("%lld", &x) == -1) exit(0);
  return x;
}
const double err = 1e-11;
const double pi = acos(-1);
double readf() {
  double x;
  if (scanf("%lf", &x) == -1) exit(0);
  return x;
}
template <typename T>
T sqr(const T &x) {
  return x * x;
}
template <typename A, typename B>
ostream &operator<<(ostream &o, const pair<A, B> &x) {
  return o << '(' << x.first << ',' << x.second << ')';
}
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 200010;
const int mod = (1 ? 1000000007 : 998244353);
long long mul(long long a, long long b, long long m = mod) { return a * b % m; }
long long qpow(long long a, long long b, long long m = mod) {
  long long ans = 1;
  for (; b; a = mul(a, a, m), b >>= 1)
    if (b & 1) ans = mul(ans, a, m);
  return ans;
}
long long getinv(long long v, long long m = mod) { return qpow(v, m - 2, m); }
set<long long> s;
long long n, a[N];
void fac(long long n) {
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) {
      s.insert(i);
      while (n % i == 0) n /= i;
    }
  if (n > 1) s.insert(n);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = (0), _ = (n); i < _; i++) cin >> a[i];
  for (long long i = (n)-1, _ = (3); i >= _; i--) swap(a[i], a[rnd() % i]);
  for (long long i = (0), _ = (min(30ll, n)); i < _; i++) {
    fac(a[i]);
    fac(a[i] + 1);
    fac(a[i] - 1);
  }
  long long ans = inf;
  for (auto d : s) {
    long long now = 0;
    for (long long i = (0), _ = (n); i < _; i++) {
      if (a[i] < d)
        now += d - a[i];
      else
        now += min(a[i] % d, d - a[i] % d);
    }
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}
