#include <bits/stdc++.h>
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target("avx2")
using namespace std;
const long long N = 2e5 + 9;
const long long Log2 = 21;
const long long mod = 1e9 + 7;
long long n, a[N], ans;
vector<long long> pr, v;
long long Get(long long val) {
  long long res = 0;
  for (long long i = 1; i <= n; i++) {
    long long cur = a[i] % val;
    if (a[i] <= val) {
      res += val - a[i];
      continue;
    }
    res += min(cur, val - cur);
  }
  return res;
}
void pt(long long x) {
  pr.clear();
  long long i = 2;
  while (x / i >= i) {
    long long tmp = 0;
    while (x % i == 0) x /= i, tmp = 1;
    if (tmp) pr.push_back(i);
    i++;
  }
  if (x > 1) pr.push_back(x);
}
void oper(long long x) {
  if (x < 2) return;
  pt(x);
  for (auto i : pr) ans = min(ans, Get(i));
}
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  if (fopen("test"
            ".inp",
            "r")) {
    freopen(
        "test"
        ".inp",
        "r", stdin);
  }
  srand(time(NULL));
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i] % 2;
    v.push_back(i);
  }
  shuffle(v.begin(), v.end(), mt);
  for (long long i = 0; i < min(40ll, (long long)v.size()); i++) {
    long long now = v[i];
    oper(a[now]);
    oper(a[now] - 1);
    oper(a[now] + 1);
  }
  cout << ans;
}
