#include <bits/stdc++.h>
using namespace std;
const int N = 210000;
const int M = 1100000;
int n;
long long a[N];
long long v[N * 2];
bool ispr[M + 5];
int calc(long long p, int up) {
  long long res = 0;
  for (int i = (int)(1); i <= (int)(n); i++) {
    if (a[i] < p)
      res += p - a[i];
    else
      res += min(p - a[i] % p, a[i] % p);
    if (res > up) return up;
  }
  return (int)res;
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%lld", &a[i]);
  int ans = calc(2, n);
  long long S = max(a[1] - n, 1ll);
  long long T = a[1] + n;
  for (int i = (int)(0); i <= (int)((int)(T - S)); i++) v[i] = i + S;
  for (int i = (int)(2); i <= (int)(M); i++)
    if (!ispr[i])
      for (int j = (int)(2); j <= (int)(n / i); j++) ispr[i * j] = 1;
  for (int i = (int)(2); i <= (int)(M); i++)
    if (!ispr[i]) {
      bool flg = 0;
      for (long long j = (i - (S % i)) % i; j <= T - S; j += i) {
        while (v[j] % i == 0) v[j] /= i;
        flg = 1;
      }
      if (flg) ans = min(ans, calc(i, ans));
    }
  for (int i = (int)(0); i <= (int)((int)(T - S)); i++)
    if (v[i] > 1) ans = min(ans, calc(v[i], ans));
  printf("%d\n", ans);
  return 0;
}
