#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  auto st = clock();
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long& x : a) cin >> x;
  shuffle(a.begin(), a.end(), rng);
  long long best = 1e18;
  set<long long> s;
  for (int i = 0; i < n; ++i) {
    if (clock() > st + 2.0 * CLOCKS_PER_SEC) break;
    for (long long j = max(1LL, a[i] - 1LL); j <= a[i] + 1; ++j) {
      vector<long long> pr;
      long long x = j;
      for (long long p = 2; p * p <= x; ++p) {
        if (x % p) continue;
        while (x % p == 0) x /= p;
        pr.push_back(p);
      }
      if (x > 1) pr.push_back(x);
      for (long long y : pr) {
        if (s.count(y)) continue;
        s.insert(y);
        long long cost = 0;
        for (long long x : a) {
          if (x < y)
            cost += y - x;
          else {
            x %= y;
            cost += min(x, y - x);
          }
          if (cost > best) break;
        }
        best = min(best, cost);
      }
    }
  }
  cout << best;
}
