#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater() {}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
long long p = 1e9 + 7;
const int N = 2e5 + 5;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int T = 1;
  while (T--) {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < (n); ++i) cin >> a[i];
    long long ans = n;
    for (int q = 0; q < (20); ++q) {
      long long ind = uniform_int_distribution<long long>(0, n - 1)(rng);
      long long x = a[ind];
      for (long long k = -1; k <= 1; k++) {
        long long y = x + k;
        if (y <= 1) continue;
        vector<long long> v;
        for (long long p = 2; p <= sqrt(y); p++) {
          if (y % p == 0) {
            v.push_back(p);
          }
          while (y % p == 0) {
            y = y / p;
          }
        }
        if (y > 1) {
          v.push_back(y);
        }
        a[ind] = x + k;
        for (auto num : v) {
          long long temp = abs(k);
          for (int i = 0; i < (n); ++i) {
            long long u = num - a[i] % num;
            if (a[i] >= num) {
              u = min(u, a[i] % num);
            }
            temp += u;
          }
          ans = min(ans, temp);
        }
        a[ind] = x;
      }
    }
    cout << ans;
  }
  timecalculater();
  return 0;
}
