#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
long long a[maxn], ans;
set<long long> se;
int prime[maxn], cnt;
bool ha[maxn];
int n;
void Prime(void) {
  ha[1] = true;
  for (int i = 2; i < maxn; i++) {
    if (!ha[i]) prime[cnt++] = i;
    for (int j = 0; j < cnt && prime[j] * i < maxn; j++) {
      ha[i * prime[j]] = true;
      if (i % prime[j] == 0) break;
    }
  }
}
void doit(long long now) {
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] <= now)
      res += now - a[i];
    else {
      long long pr = a[i] % now;
      res += min(pr, now - pr);
    }
  }
  ans = min(ans, res);
}
void check(long long now) {
  if (now == 0) return;
  for (int i = 0; i < cnt && 1ll * prime[i] * prime[i] <= now; i++) {
    if (now % prime[i]) continue;
    if (se.find(prime[i]) == se.end()) doit(prime[i]), se.insert(prime[i]);
    while (now % prime[i] == 0) now /= prime[i];
  }
  if (now > 1) {
    if (se.find(now) == se.end()) doit(now), se.insert(now);
  }
}
int main(void) {
  Prime();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  ans = n;
  srand(19981031);
  for (int i = 1; i <= 15; i++) {
    int pos = ((rand() << 15) | (rand())) % n + 1;
    check(a[pos]);
    check(a[pos] + 1);
    check(a[pos] - 1);
  }
  printf("%lld\n", ans);
  return 0;
}
