#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
long long a[maxn];
set<long long> s;
void solve(long long it) {
  for (long long i = 2; i <= sqrt(it); i++) {
    if (it % i == 0) {
      s.insert(i);
      while (it % i == 0) it /= i;
    }
  }
  if (it > 1) s.insert(it);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  set<long long> st;
  int x = 0;
  srand(233);
  random_shuffle(a + 1, a + 1 + n);
  while (x <= 30 && x < n) {
    x++;
    if (st.find(a[x]) != st.end()) continue;
    st.insert(a[x]);
  }
  for (auto it : st) {
    solve(it);
    solve(it + 1);
    solve(it - 1);
  }
  long long ans = n;
  for (auto it : s) {
    long long cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] <= it)
        cnt += it - a[i];
      else
        cnt += min(a[i] % it, it - a[i] % it);
    }
    ans = min(cnt, ans);
  }
  cout << ans << endl;
  return 0;
}
