#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
class FKuroniAndThePunishment {
 public:
  vector<long long> primes;
  void pre(int n) {
    vector<bool> isPrime(n + 1, true);
    isPrime[1] = false;
    isPrime[0] = false;
    for (int i = 2; i <= n; i++) {
      if (isPrime[i])
        for (int j = 2 * i; j <= n; j += i) isPrime[j] = false;
      if (isPrime[i]) primes.push_back(i);
    }
  }
  void solve(std::istream &in, std::ostream &out) {
    int n;
    in >> n;
    vector<long long> ar(n);
    for (long long &i : ar) in >> i;
    long long mn = LLONG_MIN;
    for (long long i : ar) mn = max(mn, i);
    pre(1000000);
    int idx = primes.size();
    for (long long i = max(1ll, mn - n); i <= mn + n; i++) primes.push_back(i);
    long long first = primes[idx];
    for (int i = 0; i < idx; i++) {
      long long index =
          idx + (first % primes[i] == 0 ? 0 : primes[i] - (first % primes[i]));
      for (long long j = index; j < primes.size(); j += primes[i])
        while (primes[j] % primes[i] == 0) primes[j] /= primes[i];
    }
    long long ans = n;
    for (long long &i : primes) {
      if (i == 1) continue;
      long long res = 0;
      for (long long &j : ar) {
        if (j < i)
          res += (i - j);
        else
          res += min(j % i, (i - (j % i)));
        if (res >= ans) break;
      }
      ans = min(ans, res);
    }
    out << ans << "\n";
  }
};
int main() {
  FKuroniAndThePunishment solver;
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
