#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
long long a[N], ans;
int random(int n) { return (long long)rand() * rand() % n; }
void check(long long x) {
  long long res = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] >= x)
      res += min(a[i] % x, x - a[i] % x);
    else
      res += x - a[i];
  ans = min(ans, res);
}
int main() {
  srand(time(0));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  ans = n;
  for (int i = 1; i <= 50; i++) {
    long long temp = a[random(n) + 1];
    for (int k = -1; k <= 1; k++) {
      long long num = temp + k;
      if (num < 1) continue;
      for (long long j = 2; j * j <= num; j++) {
        if (num % j != 0) continue;
        check(j);
        while (num % j == 0) num /= j;
      }
      if (num > 1) check(num);
    }
  }
  cout << ans << endl;
  return 0;
}
