#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
long long a[maxn];
int N;
vector<long long> divisor(long long N) {
  vector<long long> res;
  for (long long i = 2; i <= N / i; i++) {
    if (N % i == 0) {
      res.push_back(i);
      while (N % i == 0) N /= i;
    }
  }
  if (N > 1) res.push_back(N);
  return res;
}
unordered_set<long long> tried;
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%lld", &a[i]);
  long long ans = 1e9;
  for (int i = 0; i < 50; i++) {
    unordered_set<long long> primes;
    int id = rand() * rand() % N;
    for (long long j = -1; j <= 1; j++) {
      if (a[id] + j == 0LL) continue;
      vector<long long> v = divisor(a[id] + j);
      for (auto u : v) primes.insert(u);
    }
    if (i == 0) primes.insert(2);
    for (auto p : primes) {
      long long res = 0;
      if (tried.count(p)) continue;
      tried.insert(p);
      for (int j = 0; j < N; j++) {
        if (a[j] < p)
          res += p - a[j];
        else {
          res += min(a[j] % p, p - (a[j] % p));
        }
      }
      ans = min(res, ans);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
