#include <bits/stdc++.h>
using namespace std;
using lld = long long;
const lld INF = 1e9;
lld res = INF;
mt19937 seed(chrono::steady_clock().now().time_since_epoch().count());
int rand(int a, int b) { return uniform_int_distribution<int>(a, b)(seed); }
void check(vector<lld>& t, lld x) {
  vector<lld> p;
  for (lld i = 2; i * i <= x; i++)
    if (x % i == 0) {
      p.push_back(i);
      while (x % i == 0) x /= i;
    }
  if (x != 1) p.push_back(x);
  for (lld q : p) {
    lld sum = 0;
    for (lld& i : t) sum += min(q - i % q, (i / q == 0 ? q : i % q));
    res = min(res, sum);
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<lld> t(n);
  for (lld& i : t) cin >> i;
  for (int i = 0; i < 30; i++) {
    lld x = t[rand(0, n - 1)];
    for (lld j = -1; j <= 1; j++)
      if (x + j > 0) check(t, x + j);
  }
  cout << res << "\n";
  return 0;
}
