#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long a[maxn];
int n;
vector<int> prim;
bool vis[1000006];
void init() {
  int N = 1e6 + 5;
  int m = sqrt(N + 1);
  for (int i = 2; i <= m; ++i) {
    if (!vis[i])
      for (int j = i * i; j <= N; j += i) vis[j] = 1;
  }
  for (int i = 2; i <= N; ++i)
    if (!vis[i]) prim.push_back(i);
}
int ans = 0;
void work(long long x) {
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    if (x > a[i])
      res += x - a[i];
    else
      res += min(a[i] % x, x - a[i] % x);
  }
  ans = min((long long)ans, res);
  return;
}
void sol(long long x) {
  for (int i = 0; i < prim.size() && x >= prim[i]; ++i) {
    if (x % prim[i] == 0) {
      while (x % prim[i] == 0) x /= prim[i];
      work(prim[i]);
    }
  }
  if (x != 1) work(x);
  return;
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a + i);
    if (a[i] % 2 == 1) ++ans;
  }
  int T = 10;
  mt19937 rnd(time(NULL));
  while (T--) {
    int p = rnd() % n;
    if (a[p] == 1) continue;
    sol(a[p] + 1);
    if (a[p] != 1) sol(a[p]);
    if (a[p] > 2) sol(a[p] - 1);
  }
  cout << ans << endl;
  return 0;
}
