#include <bits/stdc++.h>
using namespace std;
vector<long long> primes;
long long a[300000];
long long n;
set<long long> primecheck;
void getprimes() {
  bool isprime[1000000];
  for (long long i = 2; i < 1000000; i++) {
    isprime[i] = true;
  }
  for (long long p = 2; p < 1000000; p++) {
    if (isprime[p]) {
      primes.push_back(p);
      for (long long j = 2; j < (1000000 / p); j++) {
        isprime[p * j] = false;
      }
    }
  }
}
long long dist(long long d) {
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] < d) {
      sum += d - a[i];
    } else {
      long long res = (a[i] % d);
      sum += min(res, d - res);
    }
  }
  return sum;
}
void addprimes(long long x) {
  long long y = x;
  for (long long p : primes) {
    while ((y % p) == 0) {
      y = y / p;
      primecheck.insert(p);
    }
  }
  if (y > 1) {
    primecheck.insert(y);
  }
}
int main() {
  cin >> n;
  for (long i = 0; i < n; i++) {
    cin >> a[i];
  }
  getprimes();
  for (int t = 0; t < 20; t++) {
    long long i = (rand() * rand()) % n;
    long long x = a[i];
    if (x > 1) {
      addprimes(x - 1);
    }
    addprimes(x);
    addprimes(x + 1);
  }
  long long MIN = n;
  for (long long p : primecheck) {
    MIN = min(MIN, dist(p));
  }
  cout << MIN;
  return 0;
}
