#include <bits/stdc++.h>
using namespace std;
long long nn, kor = 1000000, mini = kor;
long long w = 1;
long long tt[200001];
vector<long long> prim;
vector<pair<long long, int> > sz;
bool pr[1000001];
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(a, b % a);
}
void ch(long long a) {
  if (a < kor) prim.push_back(a);
  if (a > kor) {
    for (long long i = 0; i < prim.size(); i++) {
      long long x = prim[i];
      while ((a % x) == 0) a /= x;
      if (a < kor) return;
      if (x * x > a) break;
    }
  }
  long long sum = 0;
  for (long long i = 0; i < sz.size(); i++) {
    long long fi = sz[i].first, y = sz[i].second;
    long long x = fi % a;
    long long db = min(x, a - x);
    if (fi < a) db = a - x;
    sum += db * y;
    if (sum >= mini) return;
  }
  mini = sum;
}
long long vel() {
  long long si = sz.size();
  long long a = rand(), b = rand(), c = rand();
  return (a * b + c + w) % si;
  w++;
}
int main() {
  cin >> nn;
  for (long long i = 1; i <= nn; i++) cin >> tt[i];
  sort(tt + 1, tt + nn + 1);
  sz.push_back({tt[1], 1});
  for (int i = 2; i <= nn; i++) {
    if (tt[i] == sz.back().first)
      sz.back().second++;
    else
      sz.push_back({tt[i], 1});
  }
  for (long long i = 2; i <= kor; i++) {
    if (!pr[i]) {
      ch(i);
      for (long long j = 2 * i; j <= kor; j += i) {
        pr[kor] = true;
      }
    }
  }
  for (long long i = 1; i <= 200; i++) {
    long long a = vel();
    if (sz[a].first > kor) ch(sz[a].first);
  }
  for (long long i = 1; i <= 200; i++) {
    long long a = vel(), b = vel(), c = vel(), d = vel();
    long long e =
        gcd(abs(sz[a].first - sz[b].first), abs(sz[c].first - sz[d].first));
    if (e > kor) ch(e);
  }
  cout << mini << endl;
  return 0;
}
