#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
long long n, q;
long long a[maxn];
long long cost(long long g) {
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] < g)
      ans += g - a[i];
    else
      ans += min(a[i] % g, g - a[i] % g);
  }
  return ans;
}
long long ans = inf;
void DO(long long x) {
  if (x <= 1) return;
  for (long long i = 2; i <= sqrt(x); i++)
    if (x % i == 0) {
      ans = min(ans, cost(i));
      while (x % i == 0) x /= i;
    }
  if (x > 1) ans = min(ans, cost(x));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  random_shuffle(a + 1, a + n + 1);
  for (long long i = 1; i <= 10; i++) DO(a[i] - 1), DO(a[i]), DO(a[i] + 1);
  for (long long i = n / 3; i <= n / 3 + 15; i++)
    DO(a[i] - 1), DO(a[i]), DO(a[i] + 1);
  for (long long i = 2 * n / 3; i <= 2 * n / 3 + 15; i++)
    DO(a[i] - 1), DO(a[i]), DO(a[i] + 1);
  for (long long i = n; i >= n - 10; i--) DO(a[i] - 1), DO(a[i]), DO(a[i] + 1);
  cout << ans;
}
