#include <bits/stdc++.h>
using namespace std;
const long long Inf = 1e18;
vector<long long> Fact(long long x) {
  vector<long long> Res;
  for (long long y = 2; y * y <= x; y++)
    while (x % y == 0) Res.push_back(y), x /= y;
  if (x > 1) Res.push_back(x);
  sort(Res.begin(), Res.end());
  Res.erase(unique(Res.begin(), Res.end()), Res.end());
  return Res;
}
int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long& x : a) scanf("%I64d", &x);
  long long Ans = n;
  for (int Rep = 0; Rep < 30; Rep++) {
    int i = uniform_int_distribution<int>(0, n - 1)(rng);
    for (long long x = max(1LL, a[i] - 1); x <= a[i] + 1; x++) {
      vector<long long> P = Fact(x);
      for (long long y : P) {
        long long Res = 0;
        for (int j = 0; j < n; j++)
          Res += min(a[j] >= y ? a[j] % y : Inf, y - a[j] % y);
        Ans = min(Ans, Res);
      }
    }
  }
  cout << Ans << endl;
}
