#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 105;
int bz[M], p[M], p0;
void sieve(int n) {
  for (int i = 2, _b = n; i <= _b; i++) {
    if (!bz[i]) p[++p0] = i;
    for (int j = 1; i * p[j] <= n; j++) {
      int k = i * p[j];
      bz[k] = 1;
      if (i % p[j] == 0) break;
    }
  }
}
const int N = 2e5 + 5;
int n;
long long a[N];
long long u[1000], u0;
void fen(long long n) {
  u0 = 0;
  for (int i = 1; i <= p0 && (long long)p[i] * p[i] <= n; i++)
    if (n % p[i] == 0) {
      u[++u0] = p[i];
      while (n % p[i] == 0) n /= p[i];
    }
  if (n > 1) u[++u0] = n;
}
map<long long, int> w;
map<long long, int>::iterator it;
long long ans;
void check(long long x) {
  long long s = 0;
  for (int i = 1, _b = n; i <= _b; i++) {
    if (a[i] >= x) {
      long long y = a[i] % x;
      s += min(y, x - y);
    } else
      s += x - a[i];
    if (s > ans) return;
  }
  ans = s;
}
int main() {
  srand(time(0) + clock());
  sieve(1e6);
  scanf("%d", &n);
  for (int i = 1, _b = n; i <= _b; i++) scanf("%lld", &a[i]);
  random_shuffle(a + 1, a + n + 1);
  for (int i = 1, _b = n - 1; i <= _b; i++) {
    swap(a[i], a[rand() % n + 1]);
  }
  for (int i = 1, _b = min(n, 50); i <= _b; i++) {
    for (int j = -1, _b = 1; j <= _b; j++) {
      long long x = a[i] + j;
      if (x > 1) {
        fen(x);
        for (int k = 1, _b = u0; k <= _b; k++) w[u[k]] = 1;
      }
    }
  }
  ans = n;
  for (it = w.begin(); it != w.end(); it++) check((*it).first);
  printf("%lld\n", ans);
}
