#include <bits/stdc++.h>
using namespace std;
const int N = 1E6 + 7;
long long a[N];
int n, ans = N;
bool visited[N];
vector<int> prime, id;
set<long long> res;
void init() {
  long long seed = std::chrono::system_clock::now().time_since_epoch().count();
  shuffle(id.begin(), id.end(), default_random_engine(seed));
}
void sieve() {
  for (int i = 2; i < N; ++i)
    if (visited[i] == false) {
      prime.push_back(i);
      for (int j = i; j < N; j += i) visited[j] = true;
    }
}
void factorize(long long num) {
  for (int i = 0; i < prime.size(); ++i) {
    long long v = prime[i];
    if (num % v == 0) {
      res.insert(v);
      while (num % v == 0) num = num / v;
    }
  }
  if (num > 1) res.insert(num);
}
int answer(long long num) {
  long long tmp = 0;
  for (int i = 1; i <= n; ++i) {
    long long add_tmp = 0;
    if (a[i] < num)
      add_tmp = num - a[i];
    else
      add_tmp = min(a[i] % num, num - a[i] % num);
    tmp = min(1LL * n, tmp + add_tmp);
  }
  return tmp;
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  sieve();
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    id.push_back(i);
  }
  init();
  for (int i = 0; i < min(100, (int)id.size()); ++i) {
    int tmp = id[i];
    factorize(a[tmp]);
    factorize(a[tmp] + 1);
    if (a[tmp] > 1) factorize(a[tmp] - 1);
  }
  for (long long tmp : res) ans = min(ans, answer(tmp));
  cout << ans;
}
