#include <bits/stdc++.h>
using namespace std;
int n, n0;
int ans;
long long a[200086], b[200086];
map<long long, bool> mp;
inline void check(long long x) {
  if (x <= 1) return;
  int sup = (int)sqrt(x) + 3;
  long long j = x;
  for (int i = 2; i <= sup && j != 1; i++) {
    if (j % i == 0) {
      while (j % i == 0) j /= i;
      if (mp[i]) continue;
      mp[i] = true;
      int sum = 0;
      for (int k = 1; k <= n; k++) {
        sum += a[k] > i ? min(a[k] % i, i - a[k] % i) : i - a[k];
        if (sum >= n) break;
      }
      if (sum < ans) ans = sum;
    }
  }
  if (j ^ 1) {
    if (mp[j]) return;
    mp[j] = true;
    long long sum = 0;
    for (int k = 1; k <= n; k++) {
      sum += a[k] > j ? min(a[k] % j, j - a[k] % j) : j - a[k];
      if (sum >= n) break;
    }
    if (sum < ans) ans = sum;
  }
}
int main() {
  scanf("%d", &n), ans = n;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), b[i] = a[i];
  sort(b + 1, b + 1 + n);
  random_shuffle(b + 1, b + 1 + n);
  for (int i = 1; i <= n && clock() / (double)CLOCKS_PER_SEC < 2.0; i++)
    check(b[i] - 1), check(b[i]), check(b[i] + 1);
  printf("%d", ans);
}
