#include <bits/stdc++.h>
using namespace std;
inline void read(long long &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const long long N = 2e5 + 5, mx = 1e6;
long long n, a[N], p[N], k[mx + 5], tot, res = 1e9, used[N];
inline void Pre_work() {
  for (long long i = 2; i <= mx; ++i) {
    if (!k[i]) ++tot, p[tot] = i;
    for (long long j = 1; j <= tot && i * p[j] <= mx; ++j) {
      k[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
}
vector<long long> vc;
inline void add(long long x) {
  if (!x) return;
  for (long long i = 1; i <= tot && p[i] <= x; ++i)
    if (x % p[i] == 0) {
      if (!used[i]) vc.push_back(p[i]);
      while (x % p[i] == 0) x /= p[i];
      used[i] = 1;
    }
  if (x > 1) vc.push_back(x);
}
inline long long work(long long x) {
  long long tmp = 0;
  for (long long i = 1; i <= n; ++i)
    tmp += (a[i] < x) ? x - a[i]
                      : (a[i] % x > x - a[i] % x ? x - a[i] % x : a[i] % x);
  return tmp;
}
signed main() {
  read(n);
  Pre_work();
  srand(time(NULL));
  for (long long i = 1; i <= n; ++i) read(a[i]);
  random_shuffle(a + 1, a + n + 1);
  for (long long i = 1; i <= 100 && i <= n; ++i)
    add(a[i]), add(a[i] - 1), add(a[i] + 1);
  for (long long i = 0; i < vc.size(); ++i)
    res = (res > work(vc[i]) ? work(vc[i]) : res);
  return printf("%lld\n", res), 0;
}
