#include <bits/stdc++.h>
using namespace std;
const int INF = 2139062143;
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
const int N = 2e5 + 7;
const int M = 1e6 + 7;
int n, t;
long long ans, a[N];
bool vis[M];
inline long long calc(long long x) {
  long long ret = 0;
  for (int i = 0; i < n; i++) {
    ret += min(a[i] < x ? x - a[i] : a[i] % x, x - a[i] % x);
    if (ret >= t) break;
  }
  return ret;
}
inline void work(long long x) {
  long long en = sqrt(x);
  for (long long i = 2; i <= en; i++) {
    if (!(x % i) && !vis[i]) chkmin(ans, calc(i)), vis[i] = 1;
    while (!(x % i)) x /= i;
    if (x == 1) break;
  }
  if (x != 1) chkmin(ans, calc(x));
}
int main() {
  read(n);
  for (int i = 0; i < n; i++) {
    read(a[i]);
    if (a[i] % 2) t++;
  }
  sort(a, a + n);
  random_shuffle(a, a + n);
  ans = t;
  for (int i = 0; i < min(n, 51); i++) {
    work(a[i]);
    work(a[i] + 1);
    if (a[i] > 1) work(a[i] - 1);
  }
  printf("%lld\n", ans);
  return 0;
}
