#include <bits/stdc++.h>
using namespace std;
template <typename T>
void UpdateMax(T& a, T b) {
  if (a < b) a = b;
}
template <typename T>
void UpdateMin(T& a, T b) {
  if (a > b) a = b;
}
template <typename T>
inline void read(T& x) {
  x = 0;
  char c = getchar();
  int flag = 1;
  while (!isdigit(c)) {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= flag;
}
template <typename T>
void Unique(vector<T>& vec) {
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
template <typename T>
void Relabel(vector<T>& vec, T& value) {
  value = lower_bound(vec.begin(), vec.end(), value) - vec.begin() + 1;
}
template <typename T, typename V>
void Print(const pair<T, V>& x) {
  cout << x.first << " @ " << x.second << " | ";
}
template <typename T>
void Print(const T& x) {
  cout << x << " ";
}
template <typename T>
void Pcon(const T& x) {
  cout << "\nsize: " << x.size() << endl;
  for (const auto& item : x) Print(item);
}
std::vector<int> LABS;
template <typename T>
void Print(const T* x, int offset, int loop) {
  for (int i = 0; i <= loop; i++) {
    cout << "[";
    for (int item : LABS) cout << item - offset << ",";
    cout << i - offset << "]:";
    cout << x[i] << " ";
  }
}
template <typename T, typename... Args>
void Print(const T* f, int offset, int loop, Args... args) {
  for (int i = 0; i <= loop; i++) {
    LABS.push_back(i);
    Print(f[i], offset, args...);
    cout << endl;
    LABS.pop_back();
  }
}
clock_t start_time;
inline void SetClock() { start_time = clock(); }
bool TimeOut(size_t ms) {
  if (1000 * (clock() - start_time) >= ms * ((clock_t)1000)) return true;
  return false;
}
const int N = 2e5 + 5;
const int MAX = 1e6 + 2;
int n, Plus;
long long a[N], ans;
vector<int> Primes;
bool isPrime[MAX];
unordered_map<long long, int> freq;
void deal(long long x) {
  for (int y : Primes) {
    if (1ll * y * y > x) break;
    if (x % y == 0) {
      while (x % y == 0) x /= y;
      ++freq[y];
    }
  }
  if (x != 1) {
    ++freq[x];
  }
}
long long Calc(long long x) {
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    long long res = a[i] % x;
    if (a[i] > res)
      cnt += min(res, x - res);
    else
      cnt += x - res;
    if (cnt >= ans) {
      return cnt;
    }
  }
  return cnt;
}
int main() {
  srand(time(0));
  SetClock();
  cin.sync_with_stdio(false);
  Primes.reserve(100000);
  freq.reserve(1000);
  memset(isPrime, true, sizeof(isPrime));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      Plus++;
      a[i] = 2;
    }
  }
  for (int i = 2; i < MAX; i++) {
    if (isPrime[i]) {
      Primes.push_back(i);
      for (int j = i * 2; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  for (int i = 1; i <= 100; i++) {
    int pos = (1ll * rand() * rand()) % n + 1;
    if (a[pos] != 2) deal(a[pos] - 1);
    deal(a[pos]);
    deal(a[pos] + 1);
  }
  ans = n;
  for (const auto& item : freq) {
    UpdateMin(ans, Calc(item.first));
  }
  cout << ans + Plus << endl;
}
