#include <bits/stdc++.h>
std::mt19937 rnd(time(0));
int n, ans, prime[1000005];
bool not_prime[1000005 << 1];
long long a[1000005], S[1000005], W[1000005], seed = 191919191919ll;
long long read() {
  char c = getchar();
  long long ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    ans = (ans << 1) + (ans << 3) + (c ^ 48), c = getchar();
  return ans;
}
void Write(long long x) {
  if (x < 10)
    putchar(x ^ 48);
  else
    Write(x / 10), putchar((x % 10) ^ 48);
  return;
}
void Euler() {
  not_prime[1] = 1;
  for (register int i = 2; i <= 1100000; i++) {
    if (!not_prime[i]) prime[++prime[0]] = i;
    for (register int j = 1; j <= prime[0]; j++) {
      if (i * prime[j] > 1100000) break;
      not_prime[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
  return;
}
long long Abs(long long x) { return x < 0 ? -x : x; }
long long gcd(long long x, long long y) {
  if (x % y == 0) return y;
  return gcd(y, x % y);
}
long long min(long long x, long long y) { return x < y ? x : y; }
void check(long long p) {
  int now = 0;
  for (register int i = 1; i <= n; i++) {
    long long s = a[i] / p * p;
    if (a[i] < p)
      now += p - a[i];
    else
      now += min(a[i] - s, s + p - a[i]);
    if (now >= ans) return;
  }
  ans = now;
  return;
}
int main() {
  n = read();
  Euler();
  for (register int i = 1; i <= n; i++) a[i] = read(), ans += (a[i] & 1);
  for (register int i = 1; i <= n; i++) std::swap(a[i], a[rnd() % i + 1]);
  long long l = a[1] - n, r = a[1] + n;
  if (l < 1) l = 1;
  for (register long long i = l; i <= r; i++) W[i - l] = i;
  for (register int i = 1; i <= prime[0]; i++) check(prime[i]);
  for (register int i = 1; i <= prime[0]; i++)
    for (register long long j = (l + prime[i] - 1) / prime[i] * prime[i];
         j <= r; j += prime[i])
      while (W[j - l] % prime[i] == 0) W[j - l] /= prime[i];
  for (register long long i = l; i <= r; i++)
    if (W[i - l] != 1) check(W[i - l]);
  Write(ans);
  return 0;
}
