#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 4e18;
const long long N = 500500;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  random_shuffle((a).begin(), (a).end());
  set<long long> s;
  for (long long i = 0; i < min(n, 50LL); i++) {
    long long num = a[rand() % n];
    for (auto x : {num - 1, num, num + 1}) {
      if (x == 0) continue;
      for (long long j = 2; j * j <= x; j++) {
        if (x % j == 0) {
          s.insert(j);
          while (x % j == 0) {
            x = x / j;
          }
        }
      }
      if (x > 1) {
        s.insert(x);
      }
    }
  }
  long long ans = INF;
  for (auto p : s) {
    long long op = 0;
    for (auto w : a) {
      if (w < p) {
        op += p - w;
      } else {
        op += min(w % p, p - (w % p));
      }
    }
    ans = min(ans, op);
  }
  cout << ans;
  return 0;
}
