#include <bits/stdc++.h>
using namespace std;
template <typename G>
struct triple {
  G first, second, T;
  triple(G x, G y, G z) : first(x), second(y), T(z) {}
  triple() : first(0), second(0), T(0) {}
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int n;
  cin >> n;
  vector<long long> v(n);
  for (auto &i : v) cin >> i;
  random_shuffle(v.begin(), v.end());
  vector<long long> primes;
  auto desc = [&](long long x) {
    for (long long i = 2; i * i <= x; i++)
      if (x % i == 0) {
        primes.push_back(i);
        while (x % i == 0) x /= i;
      }
    if (x > 1) primes.push_back(x);
  };
  for (int i = 0; i < min(100, n); i++) {
    if (v[i] > 1) desc(v[i] - 1);
    desc(v[i]);
    desc(v[i] + 1);
  }
  sort(primes.begin(), primes.end());
  primes.resize(unique(primes.begin(), primes.end()) - primes.begin());
  long long ans = n;
  auto eval = [&](long long x) {
    long long temp = 0;
    for (auto &i : v) {
      if (i < x)
        temp += x - i;
      else
        temp += min(i % x, x - i % x);
    }
    ans = min(ans, temp);
  };
  for (auto &i : primes) eval(i);
  cout << ans << '\n';
  return 0;
}
