#include <bits/stdc++.h>
using namespace std;
template <typename T>
pair<std::vector<T>, std::vector<T>> linear_sieve(const T& N) {
  T tmp;
  std::vector<T> divisor(N + 1, T(0));
  std::vector<T> primes;
  primes.reserve(N >> 1);
  for (int i = 2; i <= N; ++i) {
    if (divisor[i] == 0) {
      divisor[i] = i;
      primes.push_back(i);
    }
    for (const T& p : primes) {
      if (p > divisor[i]) break;
      tmp = i * p;
      if (tmp > N) break;
      divisor[tmp] = p;
    }
  }
  primes.shrink_to_fit();
  return make_pair(move(primes), move(divisor));
}
vector<long long> prime_divisors(long long L, long long R) {
  long long sq = sqrt(R) + 1;
  vector<long long> primes = linear_sieve(sq).first;
  vector<long long> divisor(R - L + 1);
  for (int i = 0; i <= R - L; ++i) divisor[i] = i + L;
  lldiv_t tmp;
  vector<long long> res;
  for (const long long& p : primes) {
    if (R >= L + (R % p)) res.push_back(p);
    for (int i = R - (R % p) - L; i >= 0; i -= p) {
      tmp = div(divisor[i], p);
      while (tmp.rem == 0) {
        divisor[i] = tmp.quot;
        tmp = div(divisor[i], p);
      }
    }
  }
  for (int i = 0; i <= R - L; ++i) {
    if (divisor[i] > 1) res.push_back(divisor[i]);
  }
  return res;
}
int main() {
  int n;
  scanf("%u", &n);
  vector<long long> A(n);
  for (long long& a : A) scanf("%lld", &a);
  sort(A.begin(), A.end(), greater<long long>());
  vector<long long> primes =
      prime_divisors(max(1LL, A[n - 1] - n + 1), A[n - 1] + n - 1);
  long long min_dist = n, dist;
  for (const long long& p : primes) {
    dist = 0;
    for (const long long& a : A) {
      dist += (a < p) ? p - (a % p) : min(a % p, p - (a % p));
      if (dist >= min_dist) break;
    }
    if (min_dist > dist) min_dist = dist;
  }
  printf("%lld\n", min_dist);
}
