#include <bits/stdc++.h>
using ll = long long;
const int C = 1000001;
const ll MAX = 1000000000000;
void supfactor(int* pr, int v) {
  int i, j;
  pr[1] = 1;
  for (i = 2; i * i < v; i++) {
    if (pr[i] == 0) {
      for (j = i; j < v; j += i) {
        if (pr[j] == 0) pr[j] = i;
      }
    }
  }
  for (; i < v; i++)
    if (pr[i] == 0) pr[i] = i;
}
void generate_partial_sieve(ll partial[], ll vleft, ll vright, int sieve[],
                            int ln) {
  ll i, j, left;
  for (i = vleft; i <= vright; i++) partial[i - vleft] = i;
  for (i = 2; i < ln; i++) {
    if (sieve[i] != i) continue;
    left = vleft + (vleft % i == 0 ? 0 : (i - vleft % i));
    for (j = left; j <= vright; j += i) {
      while (partial[j - vleft] % i == 0) partial[j - vleft] /= i;
    }
  }
}
ll check_sum(ll prime, ll minne, ll a[], int n) {
  ll summa = 0, tmp;
  for (int j = 0; j < n; j++) {
    tmp = a[j] % prime;
    if (a[j] > prime)
      summa += (((tmp) < (prime - tmp)) ? (tmp) : (prime - tmp));
    else if (a[j] % prime != 0)
      summa += prime - tmp;
    if (summa > minne) break;
  }
  return summa;
}
int pr[C];
ll a[C], value[C];
int main() {
  int i, n;
  supfactor(pr, C);
  scanf("%d", &n);
  for (i = 0; i < C; i++) scanf("%lld", &a[i]);
  ll minne = n, summa = 0, vleft = (((a[0] - n) > (1)) ? (a[0] - n) : (1)),
     vright = (((a[0] + n) < (MAX)) ? (a[0] + n) : (MAX));
  generate_partial_sieve(value, vleft, vright, pr, C);
  for (i = 2; i < C; i++) {
    if (pr[i] != i) continue;
    summa = check_sum(i, minne, a, n);
    if (summa < minne) minne = summa;
  }
  for (i = vleft; i <= vright; i++) {
    if (value[i - vleft] == 1) continue;
    summa = check_sum(value[i - vleft], minne, a, n);
    if (summa < minne) minne = summa;
  }
  printf("%lld\n", minne);
  return 0;
}
