#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5, N = 2e5 + 10;
int n;
long long a[N];
int prime[maxn], visit[maxn], pcnt = 0;
void init() {
  for (int i = 2; i < maxn; ++i) {
    if (!visit[i]) prime[++pcnt] = i;
    for (int j = 1; j <= pcnt && i * prime[j] < maxn; ++j) {
      visit[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
set<long long> s;
void solve(long long n) {
  for (int i = 1; 1ll * prime[i] * prime[i] <= n; ++i) {
    if (n % prime[i] == 0) {
      s.insert(prime[i]);
      while (n % prime[i] == 0) n /= prime[i];
    }
  }
  if (n > 1) s.insert(n);
}
int main() {
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  shuffle(a + 1, a + 1 + n, default_random_engine(time(0)));
  for (int i = 1; i <= min(n, 30); ++i) {
    solve(a[i]);
    solve(a[i] + 1);
    if (a[i] - 1 > 0) solve(a[i] - 1);
  }
  long long ans = 9e18;
  s.insert(2);
  for (auto x : s) {
    long long res = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] < x)
        res += x - a[i];
      else
        res += min(a[i] % x, x - a[i] % x);
    }
    ans = min(ans, res);
  }
  printf("%lld\n", ans);
  return 0;
}
