#include <bits/stdc++.h>
using namespace std;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 2e5 + 7;
const int M = 1e6 + 10;
int min_div[M];
vector<int> primes;
int n;
long long a[N];
long long get(long long t) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % t == 0) continue;
    long long cur = t - a[i] % t;
    if (a[i] > t) cur = min(cur, a[i] % t);
    sum += cur;
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < M; i++) min_div[i] = i;
  for (int i = 2; i < M; i++) {
    if (min_div[i] == i) {
      primes.push_back(i);
      for (int j = i + i; j < M; j += i) min_div[j] = min(min_div[j], i);
    }
  }
  long long ans = n;
  for (int it = 0; it < 50; it++) {
    int id = gen() % n;
    for (auto val : {a[id] - 1, a[id], a[id] + 1}) {
      if (val < 1) continue;
      for (int p : primes) {
        if (val % p == 0) {
          ans = min(ans, get(p));
          while (val % p == 0) val /= p;
        }
      }
      if (val > 1) ans = min(ans, get(val));
    }
  }
  cout << ans << endl;
  return 0;
}
