#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   const int E = 80;   vector<long long> pr, f;   mt19937_64 gen(time(0));   long long a[maxn];   map<long long, long long> val;   int n;   long long solve(long long p) {     if (val.find(p) != val.end()) return val[p];     long long ret = 0;     for (int i = 0; i < n; i++) {       if (a[i] < p)         ret += p - a[i];       else {         long long h = a[i] % p;         ret += min(h, p - h);       }     }     val[p] = ret;     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     for (int i = 0; i < n; i++) {       f.push_back(a[i] + 1);       if (a[i] > 1) f.push_back(a[i]);       if (a[i] > 2) f.push_back(a[i] - 1);     }     int m = f.size();     long long ans = n;     for (int _ = 0; _ < E; _++) {       long long x = f[gen() % m], j = 2;       f.clear();       while (j * j <= x) {         if (x % j == 0) {           while (x % j == 0) x /= j;           pr.push_back(j);         }         ++j;       }       if (x > 1) pr.push_back(x);       for (auto p : pr) ans = min(ans, solve(p));     }     printf( %lld n , ans);     return 0;   }   