#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 998244353;
bool isp(int x) {
  for (int i = 2; i <= (int)sqrt(x); i++) {
    if (x % i) {
      return 0;
    }
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  srand(time(NULL));
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  random_shuffle(v.begin(), v.end());
  set<long long> prime;
  int t = 80;
  set<long long> num;
  while (t--) {
    int rnd = rand() % n;
    for (long long z = max(v[rnd] - 1, 0LL); z <= v[rnd] + 1; z++) {
      long long x = z;
      if (num.count(x)) {
        continue;
      }
      for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0) {
          prime.insert(i);
        }
        while (x % i == 0) {
          x /= i;
        }
      }
      if (x > 1) {
        prime.insert(x);
      }
    }
  }
  for (int i = 2; i <= 100; i++) {
    if (isp(i)) {
      prime.insert(i);
    }
  }
  long long ans = 1e18;
  for (auto i : prime) {
    long long cnt = 0;
    for (auto j : v) {
      long long md = j % i;
      md = min(md, i - md);
      if (j < i) {
        md = i - j;
      }
      cnt += md;
      if (cnt > ans) {
        break;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}
