#include <bits/stdc++.h>
using namespace std;
bool prim[1000001] = {};
long long buffer[20];
vector<long long> primek;
long long Megold(vector<long long> &v, long long num) {
  int veg = 0;
  for (int i = 0; i < primek.size(); i++) {
    if (num % primek[i] == 0) {
      buffer[veg++] = primek[i];
      while (num % primek[i] == 0) num /= primek[i];
    }
  }
  if (num != 1) buffer[veg++] = num;
  long long ret = 1e9;
  for (int i = 0; i < veg; i++) {
    long long akt = 0;
    for (int j = 0; j < v.size(); j++)
      akt += min((buffer[i] <= v[j] ? v[j] % buffer[i] : (long long)1e15),
                 buffer[i] - v[j] % buffer[i]);
    ret = min(ret, akt);
  }
  return ret;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  for (int i = 2; i < (int)1e6 + 1; i++) prim[i] = true;
  for (int i = 2; i < (int)1e6 + 1; i++)
    for (int j = 2 * i; j < (int)1e6 + 1 && prim[i]; j += i) prim[j] = false;
  for (int i = 2; i < (int)1e6 + 1; i++)
    if (prim[i]) primek.push_back(i);
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  long long meg = 1e9;
  mt19937 rng(
      (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
  for (int i = 0; i < 20; i++) {
    int x = rng() % n;
    for (int j = -1; j < 2; j++)
      if (v[x] + (long long)j > (long long)1)
        meg = min(meg, Megold(v, v[x] + (long long)j));
  }
  cout << meg << "\n";
  return 0;
}
