#include <bits/stdc++.h>
using namespace std;
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < 48) c = getchar();
  while (c > 47) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x;
}
const int maxn = 2e5 + 10;
int n;
long long a[maxn];
vector<long long> divisors;
inline long long mul(long long a, long long b, long long mod) {
  return (a * b - (long long)((long double)a / mod * b + 0.5) * mod + mod) %
         mod;
}
inline long long qp(long long x, long long y, long long mod) {
  long long res = 1;
  for (; y; y >>= 1, x = (long long)mul(x, x, mod))
    if (y & 1) res = mul(res, x, mod);
  return res;
}
inline long long gcd(long long a, long long b) {
  if (!a) return b;
  if (!b) return a;
  register int t = __builtin_ctzll(a | b);
  a >>= __builtin_ctzll(a);
  do {
    b >>= __builtin_ctzll(b);
    if (a > b) {
      long long t = b;
      b = a, a = t;
    }
    b -= a;
  } while (b);
  return a << t;
}
const int _A[] = {2, 3, 5, 7, 13, 61, 131};
inline bool pd(long long n) {
  if (n == 2 || n == 3) return 1;
  if (n % 2 == 0 || n == 1 || (n % 6 != 1 && n % 6 != 5)) return 0;
  long long tmp = n - 1;
  int ct = 0;
  while (!(tmp & 1)) tmp >>= 1, ct++;
  for (int i = (0), iend = (6); i <= iend; ++i) {
    if (n == _A[i]) return true;
    long long a = qp(_A[i], tmp, n), nxt = a;
    for (int j = 1; j <= ct; j++) {
      nxt = mul(a, a, n);
      if (nxt == 1 && a != 1 && a != n - 1) return false;
      a = nxt;
    }
    if (a != 1) return false;
  }
  return true;
}
inline long long _abs(long long x) { return x >= 0 ? x : -x; }
inline long long _rand() {
  return ((unsigned long long)Rnd()) << 30 | ((unsigned)Rnd());
}
inline long long _rand(long long x, long long c, long long mod) {
  return (mul(x, x, mod) + c) % mod;
}
inline long long Pollard_Rho(long long n) {
  long long s = 0, t = 0, c = _rand() % (n - 1) + 1, val = 1;
  for (int cir = 1;; cir <<= 1, s = t, val = 1) {
    for (int i = 0; i < cir; i++) {
      t = _rand(t, c, n), val = mul(val, _abs(t - s), n);
      if (i % 127 == 0) {
        long long g = gcd(val, n);
        if (g != 1) return g;
      }
    }
    long long g = gcd(val, n);
    if (g != 1) return g;
  }
}
void Factor(long long n) {
  if (n == 1) return;
  if (pd(n)) return divisors.push_back(n), void();
  long long d = n;
  while (d == n) d = Pollard_Rho(n);
  while (n % d == 0) n /= d;
  Factor(n), Factor(d);
}
set<long long> S;
int res;
void check(long long num) {
  long long cur = 0;
  for (int i = (1), iend = (n); i <= iend; ++i) {
    long long val = a[i] / num * num;
    if (val) {
      cur += min(val + num - a[i], a[i] - val);
    } else {
      cur += val + num - a[i];
    }
    if (cur > res) return;
  }
  res = cur;
}
inline int abso(int x) { return x < 0 ? -x : x; }
inline int getrnd() {
  int x;
  do {
    x = abso(Rnd());
  } while (x < 0);
  return x;
}
int main() {
  n = read();
  for (int i = (1), iend = (n); i <= iend; ++i) {
    scanf("%I64d", a + i);
    res += a[i] % 2;
  }
  int T = 505;
  while (T-- > 0 && S.size() < 600) {
    int pos;
    long long val;
    do {
      pos = getrnd() % n + 1;
      val = a[pos] - 1 + (getrnd() % 3);
    } while (val < 2);
    divisors.clear();
    Factor(val);
    for (long long x : divisors) {
      if (x > 50) {
        S.insert(x);
      }
    }
  }
  for (int num = (3), numend = (50); num <= numend; ++num) {
    if (pd(num)) check(num);
  }
  for (long long x : S) {
    check(x);
  }
  cout << res;
  return 0;
}
