#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define INF 2147483647
#define LLINF LLONG_MAX
#define PI 3.1415926535
#define MOD 1000000007
#define MOD2 998244353
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CASE(x) int x; cin >> x; while (x--)
#define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc)
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
namespace {
	typedef long long ll;
	typedef unsigned long long ull;
	typedef pair<int,int> pii;
	typedef pair<ll,ll> pll;
	template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
	template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
	template <class T> using maxheap = priority_queue<T, vector<T>, greater<T>>;
	template <int MODVALUE>
	struct Modular {
	private:
		long long val;

		template<class T>
		static Modular toModular(const T& m) {
			long long val = m;
			if (val < 0) val += MODVALUE;
			if (val >= MODVALUE) val -= MODVALUE;
			return Modular(val);
		}

	public:
		bool operator == (const Modular& other) {return val == other.val;}
		bool operator != (const Modular& other) {return !(val == other.val);}
		template<class T> bool operator == (const T& other) {return *this == Modular(other);}
		template<class T> bool operator != (const T& other) {return !(*this == Modular(other));}
		template<class T> friend bool operator == (const T& other, const Modular& m) {return Modular(other) == m;}
		template<class T> friend bool operator != (const T& other, const Modular& m) {return !(Modular(other) == m);}

		bool operator < (const Modular& other) {return val < other.val;}
		bool operator <= (const Modular& other) {return val <= other.val;}
		bool operator > (const Modular& other) {return val > other.val;}
		bool operator >= (const Modular& other) {return val >= other.val;}
		template<class T> bool operator < (const T& other) {return *this < Modular(other);}
		template<class T> bool operator <= (const T& other) {return *this <= Modular(other);}
		template<class T> bool operator > (const T& other) {return *this > Modular(other);}
		template<class T> bool operator >= (const T& other) {return *this >= Modular(other);}
		template<class T> friend bool operator < (const T& other, const Modular& m) {return Modular(other) < m;}
		template<class T> friend bool operator <= (const T& other, const Modular& m) {return Modular(other) <= m;}
		template<class T> friend bool operator > (const T& other, const Modular& m) {return Modular(other) > m;}
		template<class T> friend bool operator >= (const T& other, const Modular& m) {return Modular(other) >= m;}

		Modular operator + (const Modular& other) {return toModular(val + other.val);}
		Modular& operator += (const Modular& other) {return *this = *this + other;}
		template<class T> Modular operator + (const T& other) {return *this + Modular(other);}
		template<class T> Modular& operator += (const T& other) {return *this += Modular(other);}
		template<class T> friend Modular operator + (const T& other, const Modular& m) {return Modular(other) + m;}
		template<class T> friend Modular operator += (const T& other, const Modular& m) {return Modular(other) += m;}

		Modular& operator ++() {return *this += 1;}
		Modular operator ++(int) {Modular tmp = *this; ++*this; return tmp;}

		Modular operator - () const {return Modular(-val);}
		Modular operator - (const Modular& other) {return toModular(val - other.val);}
		Modular& operator -= (const Modular& other) {return *this = *this - other;}
		template<class T> Modular operator - (const T& other) {return *this - Modular(other);}
		template<class T> Modular& operator -= (const T& other) {return *this -= Modular(other);}
		template<class T> friend Modular operator - (const T& other, const Modular& m) {return Modular(other) - m;}
		template<class T> friend Modular operator -= (const T& other, const Modular& m) {return Modular(other) -= m;}

		Modular& operator --() {return *this -= 1;}
		Modular operator --(int) {Modular tmp = *this; --*this; return tmp;}

		Modular operator * (const Modular& other) {return toModular(val * other.val % MODVALUE);}
		Modular& operator *= (const Modular& other) {return *this = *this * other;}
		template<class T> Modular operator * (const T& other) {return *this * Modular(other);}
		template<class T> Modular operator *= (const T& other) {return *this *= Modular(other);}
		template<class T> friend Modular operator * (const T& other, const Modular& m) {return Modular(other) * m;}
		template<class T> friend Modular operator *= (const T& other, const Modular& m) {return Modular(other) *= m;}

		Modular pow(long long power) {
			Modular m = *this, ans = 1;
			while (power) {
				if (power & 1) ans *= m;
				m *= m;
				power >>= 1;
			}
			return ans;
		}
		Modular pow(Modular& other) {return pow(other.val);}
		Modular inv() {return pow(MODVALUE-2);}

		Modular operator / (const Modular& other) {return *this * other;}
		Modular operator /= (const Modular& other) {return *this = *this / other;}
		template<class T> Modular operator / (const T& other) {return *this / Modular(other);}
		template<class T> Modular operator /= (const T& other) {return *this /= Modular(other);}
		template<class T> friend Modular operator / (const T& other, const Modular& m) {return Modular(other) / m;}
		template<class T> friend Modular operator /= (const T& other, const Modular& m) {return Modular(other) /= m;}

		friend istream& operator >> (istream& in, Modular& m) {in >> m.val; m = toModular(m.val % MODVALUE); return in;}
		friend ostream& operator << (ostream& out, const Modular& m) {return out << m.val;}

		Modular() : val(0) {}
		Modular(int val) : val(val % MODVALUE) {};
		Modular(long long val) : val(val % MODVALUE) {};
	};
}
namespace input {
	template<class T> inline void _R(T &x) {cin >> x;}
	template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);}
	template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);}
	inline void R() {}
	template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);}
} using namespace input;
namespace output {
	template<class T> inline void _W(const T& x);
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p);
	template<class T> inline void _W(const vector<T>& x);
	template<class T> inline void _W(const deque<T>& x);
	template<class T> inline void _W(const forward_list<T>& x);
	template<class T> inline void _W(const list<T>& x);
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x);
	template<class T> inline void _W(const multiset<T>& x);
	template<class T> inline void _W(const unordered_set<T>& x);
	template<class T> inline void _W(const unordered_multiset<T>& x);
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x);
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x);

	template<class T> inline void _W(const T& x) {cout << x;}
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);}
	template<class T> inline void _W(const vector<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const deque<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const forward_list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

	template<class T> inline void _W(const ordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

 	inline void W() {cout << '\n';}
	template<class T> inline void W(const T &x) {_W(x); W();}
	template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);}
} using namespace output;
namespace output_format{
	inline string Case(int tc) {return "Case #" + to_string(tc) + ':';}
	inline string YN(bool b) {return b ? "YES" : "NO";}
} using namespace output_format;
namespace utility{
	inline ll pow(ll b, ll p, ll mod) {
		b %= mod;
		ll ans = 1;
		for (; p > 0; p >>= 1) {
			if (p&1) {ans *= b; ans %= mod;}
			b *= b;
			b %= mod;
		}
		return ans;
	}
	inline bool chkmin(ll& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(ll& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, int y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, int y) {return x < y ? x = y, 1 : 0;}
} using namespace utility;
namespace std {
    template <class T1, class T2> struct hash<pair<T1,T2>> {
    	std::size_t operator()(pair<T1,T2> _) const {
        	return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
    	}
    };
}
using Mint = Modular<MOD>;

int main() {
	int n; R(n);
	vector<ll> a(n); R(a);

	ll gcd = 0;
	for (int i = 0; i < n; i++)
		gcd = __gcd(gcd, a[i]);

	if (gcd > 1) {
		W(0);
		return 0;
	}

	ll ans = INF;
	for (int i = 2; clock() <= 2400; i++) {
		ll sum = 0;
		for (auto& j : a) {
			ll below = j / i;
			ll high = below + 1;
			if (below == 0)
				sum += (high * i - j);
			else
				sum +- min(high * i - j, j - low * i);
		}
		chkmin(ans, sum);
	}

	W(ans);

	return 0;
}

static auto _batch_ios = [](){
	#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);
	#endif
	cout << fixed << setprecision(10);
	return 42;
}();


#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define INF 2147483647
#define LLINF LLONG_MAX
#define PI 3.1415926535
#define MOD 1000000007
#define MOD2 998244353
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CASE(x) int x; cin >> x; while (x--)
#define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc)
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
namespace {
	typedef long long ll;
	typedef unsigned long long ull;
	typedef pair<int,int> pii;
	typedef pair<ll,ll> pll;
	template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
	template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
	template <class T> using maxheap = priority_queue<T, vector<T>, greater<T>>;
	template <int MODVALUE>
	struct Modular {
	private:
		long long val;

		template<class T>
		static Modular toModular(const T& m) {
			long long val = m;
			if (val < 0) val += MODVALUE;
			if (val >= MODVALUE) val -= MODVALUE;
			return Modular(val);
		}

	public:
		bool operator == (const Modular& other) {return val == other.val;}
		bool operator != (const Modular& other) {return !(val == other.val);}
		template<class T> bool operator == (const T& other) {return *this == Modular(other);}
		template<class T> bool operator != (const T& other) {return !(*this == Modular(other));}
		template<class T> friend bool operator == (const T& other, const Modular& m) {return Modular(other) == m;}
		template<class T> friend bool operator != (const T& other, const Modular& m) {return !(Modular(other) == m);}

		bool operator < (const Modular& other) {return val < other.val;}
		bool operator <= (const Modular& other) {return val <= other.val;}
		bool operator > (const Modular& other) {return val > other.val;}
		bool operator >= (const Modular& other) {return val >= other.val;}
		template<class T> bool operator < (const T& other) {return *this < Modular(other);}
		template<class T> bool operator <= (const T& other) {return *this <= Modular(other);}
		template<class T> bool operator > (const T& other) {return *this > Modular(other);}
		template<class T> bool operator >= (const T& other) {return *this >= Modular(other);}
		template<class T> friend bool operator < (const T& other, const Modular& m) {return Modular(other) < m;}
		template<class T> friend bool operator <= (const T& other, const Modular& m) {return Modular(other) <= m;}
		template<class T> friend bool operator > (const T& other, const Modular& m) {return Modular(other) > m;}
		template<class T> friend bool operator >= (const T& other, const Modular& m) {return Modular(other) >= m;}

		Modular operator + (const Modular& other) {return toModular(val + other.val);}
		Modular& operator += (const Modular& other) {return *this = *this + other;}
		template<class T> Modular operator + (const T& other) {return *this + Modular(other);}
		template<class T> Modular& operator += (const T& other) {return *this += Modular(other);}
		template<class T> friend Modular operator + (const T& other, const Modular& m) {return Modular(other) + m;}
		template<class T> friend Modular operator += (const T& other, const Modular& m) {return Modular(other) += m;}

		Modular& operator ++() {return *this += 1;}
		Modular operator ++(int) {Modular tmp = *this; ++*this; return tmp;}

		Modular operator - () const {return Modular(-val);}
		Modular operator - (const Modular& other) {return toModular(val - other.val);}
		Modular& operator -= (const Modular& other) {return *this = *this - other;}
		template<class T> Modular operator - (const T& other) {return *this - Modular(other);}
		template<class T> Modular& operator -= (const T& other) {return *this -= Modular(other);}
		template<class T> friend Modular operator - (const T& other, const Modular& m) {return Modular(other) - m;}
		template<class T> friend Modular operator -= (const T& other, const Modular& m) {return Modular(other) -= m;}

		Modular& operator --() {return *this -= 1;}
		Modular operator --(int) {Modular tmp = *this; --*this; return tmp;}

		Modular operator * (const Modular& other) {return toModular(val * other.val % MODVALUE);}
		Modular& operator *= (const Modular& other) {return *this = *this * other;}
		template<class T> Modular operator * (const T& other) {return *this * Modular(other);}
		template<class T> Modular operator *= (const T& other) {return *this *= Modular(other);}
		template<class T> friend Modular operator * (const T& other, const Modular& m) {return Modular(other) * m;}
		template<class T> friend Modular operator *= (const T& other, const Modular& m) {return Modular(other) *= m;}

		Modular pow(long long power) {
			Modular m = *this, ans = 1;
			while (power) {
				if (power & 1) ans *= m;
				m *= m;
				power >>= 1;
			}
			return ans;
		}
		Modular pow(Modular& other) {return pow(other.val);}
		Modular inv() {return pow(MODVALUE-2);}

		Modular operator / (const Modular& other) {return *this * other;}
		Modular operator /= (const Modular& other) {return *this = *this / other;}
		template<class T> Modular operator / (const T& other) {return *this / Modular(other);}
		template<class T> Modular operator /= (const T& other) {return *this /= Modular(other);}
		template<class T> friend Modular operator / (const T& other, const Modular& m) {return Modular(other) / m;}
		template<class T> friend Modular operator /= (const T& other, const Modular& m) {return Modular(other) /= m;}

		friend istream& operator >> (istream& in, Modular& m) {in >> m.val; m = toModular(m.val % MODVALUE); return in;}
		friend ostream& operator << (ostream& out, const Modular& m) {return out << m.val;}

		Modular() : val(0) {}
		Modular(int val) : val(val % MODVALUE) {};
		Modular(long long val) : val(val % MODVALUE) {};
	};
}
namespace input {
	template<class T> inline void _R(T &x) {cin >> x;}
	template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);}
	template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);}
	inline void R() {}
	template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);}
} using namespace input;
namespace output {
	template<class T> inline void _W(const T& x);
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p);
	template<class T> inline void _W(const vector<T>& x);
	template<class T> inline void _W(const deque<T>& x);
	template<class T> inline void _W(const forward_list<T>& x);
	template<class T> inline void _W(const list<T>& x);
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x);
	template<class T> inline void _W(const multiset<T>& x);
	template<class T> inline void _W(const unordered_set<T>& x);
	template<class T> inline void _W(const unordered_multiset<T>& x);
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x);
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x);

	template<class T> inline void _W(const T& x) {cout << x;}
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);}
	template<class T> inline void _W(const vector<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const deque<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const forward_list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

	template<class T> inline void _W(const ordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

 	inline void W() {cout << '\n';}
	template<class T> inline void W(const T &x) {_W(x); W();}
	template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);}
} using namespace output;
namespace output_format{
	inline string Case(int tc) {return "Case #" + to_string(tc) + ':';}
	inline string YN(bool b) {return b ? "YES" : "NO";}
} using namespace output_format;
namespace utility{
	inline ll pow(ll b, ll p, ll mod) {
		b %= mod;
		ll ans = 1;
		for (; p > 0; p >>= 1) {
			if (p&1) {ans *= b; ans %= mod;}
			b *= b;
			b %= mod;
		}
		return ans;
	}
	inline bool chkmin(ll& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(ll& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, int y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, int y) {return x < y ? x = y, 1 : 0;}
} using namespace utility;
namespace std {
    template <class T1, class T2> struct hash<pair<T1,T2>> {
    	std::size_t operator()(pair<T1,T2> _) const {
        	return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
    	}
    };
}
using Mint = Modular<MOD>;

int main() {
	int n; R(n);
	vector<ll> a(n); R(a);

	ll gcd = 0;
	for (int i = 0; i < n; i++)
		gcd = __gcd(gcd, a[i]);

	if (gcd > 1) {
		W(0);
		return 0;
	}

	ll ans = INF;
	for (int i = 2; clock() <= 2400; i++) {
		ll sum = 0;
		for (auto& j : a) {
			ll below = j / i;
			ll high = below + 1;
			if (below == 0)
				sum += (high * i - j);
			else
				sum += min(high * i - j, j - below * i);

			if (sum > ans)
				break;
		}
		chkmin(ans, sum);
	}

	W(ans);

	return 0;
}

static auto _batch_ios = [](){
	#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);
	#endif
	cout << fixed << setprecision(10);
	return 42;
}();


#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define INF 2147483647
#define LLINF LLONG_MAX
#define PI 3.1415926535
#define MOD 1000000007
#define MOD2 998244353
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CASE(x) int x; cin >> x; while (x--)
#define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc)
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
namespace {
	typedef long long ll;
	typedef unsigned long long ull;
	typedef pair<int,int> pii;
	typedef pair<ll,ll> pll;
	template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
	template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
	template <class T> using maxheap = priority_queue<T, vector<T>, greater<T>>;
	template <int MODVALUE>
	struct Modular {
	private:
		long long val;

		template<class T>
		static Modular toModular(const T& m) {
			long long val = m;
			if (val < 0) val += MODVALUE;
			if (val >= MODVALUE) val -= MODVALUE;
			return Modular(val);
		}

	public:
		bool operator == (const Modular& other) {return val == other.val;}
		bool operator != (const Modular& other) {return !(val == other.val);}
		template<class T> bool operator == (const T& other) {return *this == Modular(other);}
		template<class T> bool operator != (const T& other) {return !(*this == Modular(other));}
		template<class T> friend bool operator == (const T& other, const Modular& m) {return Modular(other) == m;}
		template<class T> friend bool operator != (const T& other, const Modular& m) {return !(Modular(other) == m);}

		bool operator < (const Modular& other) {return val < other.val;}
		bool operator <= (const Modular& other) {return val <= other.val;}
		bool operator > (const Modular& other) {return val > other.val;}
		bool operator >= (const Modular& other) {return val >= other.val;}
		template<class T> bool operator < (const T& other) {return *this < Modular(other);}
		template<class T> bool operator <= (const T& other) {return *this <= Modular(other);}
		template<class T> bool operator > (const T& other) {return *this > Modular(other);}
		template<class T> bool operator >= (const T& other) {return *this >= Modular(other);}
		template<class T> friend bool operator < (const T& other, const Modular& m) {return Modular(other) < m;}
		template<class T> friend bool operator <= (const T& other, const Modular& m) {return Modular(other) <= m;}
		template<class T> friend bool operator > (const T& other, const Modular& m) {return Modular(other) > m;}
		template<class T> friend bool operator >= (const T& other, const Modular& m) {return Modular(other) >= m;}

		Modular operator + (const Modular& other) {return toModular(val + other.val);}
		Modular& operator += (const Modular& other) {return *this = *this + other;}
		template<class T> Modular operator + (const T& other) {return *this + Modular(other);}
		template<class T> Modular& operator += (const T& other) {return *this += Modular(other);}
		template<class T> friend Modular operator + (const T& other, const Modular& m) {return Modular(other) + m;}
		template<class T> friend Modular operator += (const T& other, const Modular& m) {return Modular(other) += m;}

		Modular& operator ++() {return *this += 1;}
		Modular operator ++(int) {Modular tmp = *this; ++*this; return tmp;}

		Modular operator - () const {return Modular(-val);}
		Modular operator - (const Modular& other) {return toModular(val - other.val);}
		Modular& operator -= (const Modular& other) {return *this = *this - other;}
		template<class T> Modular operator - (const T& other) {return *this - Modular(other);}
		template<class T> Modular& operator -= (const T& other) {return *this -= Modular(other);}
		template<class T> friend Modular operator - (const T& other, const Modular& m) {return Modular(other) - m;}
		template<class T> friend Modular operator -= (const T& other, const Modular& m) {return Modular(other) -= m;}

		Modular& operator --() {return *this -= 1;}
		Modular operator --(int) {Modular tmp = *this; --*this; return tmp;}

		Modular operator * (const Modular& other) {return toModular(val * other.val % MODVALUE);}
		Modular& operator *= (const Modular& other) {return *this = *this * other;}
		template<class T> Modular operator * (const T& other) {return *this * Modular(other);}
		template<class T> Modular operator *= (const T& other) {return *this *= Modular(other);}
		template<class T> friend Modular operator * (const T& other, const Modular& m) {return Modular(other) * m;}
		template<class T> friend Modular operator *= (const T& other, const Modular& m) {return Modular(other) *= m;}

		Modular pow(long long power) {
			Modular m = *this, ans = 1;
			while (power) {
				if (power & 1) ans *= m;
				m *= m;
				power >>= 1;
			}
			return ans;
		}
		Modular pow(Modular& other) {return pow(other.val);}
		Modular inv() {return pow(MODVALUE-2);}

		Modular operator / (const Modular& other) {return *this * other;}
		Modular operator /= (const Modular& other) {return *this = *this / other;}
		template<class T> Modular operator / (const T& other) {return *this / Modular(other);}
		template<class T> Modular operator /= (const T& other) {return *this /= Modular(other);}
		template<class T> friend Modular operator / (const T& other, const Modular& m) {return Modular(other) / m;}
		template<class T> friend Modular operator /= (const T& other, const Modular& m) {return Modular(other) /= m;}

		friend istream& operator >> (istream& in, Modular& m) {in >> m.val; m = toModular(m.val % MODVALUE); return in;}
		friend ostream& operator << (ostream& out, const Modular& m) {return out << m.val;}

		Modular() : val(0) {}
		Modular(int val) : val(val % MODVALUE) {};
		Modular(long long val) : val(val % MODVALUE) {};
	};
}
namespace input {
	template<class T> inline void _R(T &x) {cin >> x;}
	template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);}
	template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);}
	inline void R() {}
	template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);}
} using namespace input;
namespace output {
	template<class T> inline void _W(const T& x);
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p);
	template<class T> inline void _W(const vector<T>& x);
	template<class T> inline void _W(const deque<T>& x);
	template<class T> inline void _W(const forward_list<T>& x);
	template<class T> inline void _W(const list<T>& x);
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x);
	template<class T> inline void _W(const multiset<T>& x);
	template<class T> inline void _W(const unordered_set<T>& x);
	template<class T> inline void _W(const unordered_multiset<T>& x);
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x);
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x);

	template<class T> inline void _W(const T& x) {cout << x;}
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);}
	template<class T> inline void _W(const vector<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const deque<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const forward_list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

	template<class T> inline void _W(const ordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

 	inline void W() {cout << '\n';}
	template<class T> inline void W(const T &x) {_W(x); W();}
	template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);}
} using namespace output;
namespace output_format{
	inline string Case(int tc) {return "Case #" + to_string(tc) + ':';}
	inline string YN(bool b) {return b ? "YES" : "NO";}
} using namespace output_format;
namespace utility{
	inline ll pow(ll b, ll p, ll mod) {
		b %= mod;
		ll ans = 1;
		for (; p > 0; p >>= 1) {
			if (p&1) {ans *= b; ans %= mod;}
			b *= b;
			b %= mod;
		}
		return ans;
	}
	inline bool chkmin(ll& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(ll& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, int y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, int y) {return x < y ? x = y, 1 : 0;}
} using namespace utility;
namespace std {
    template <class T1, class T2> struct hash<pair<T1,T2>> {
    	std::size_t operator()(pair<T1,T2> _) const {
        	return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
    	}
    };
}
using Mint = Modular<MOD>;

template<class T>
struct primeSieve{
	int maxN = 0;
	vector<int> primes;
	vector<bool> isComposite;
	vector<int> min_divisor;

	vector<pair<T,int> > factorize(T x) {
		assert(x > 1);

		vector<pair<T,int> > factors;
		if (x <= maxN) {
			int cur = -1, cnt = -1;
			while (x != 1) {
				if (min_divisor[x] == cur) {
					cnt++;
					x /= cur;
				} else {
					if (cur != -1) {
						factors.push_back({cur,cnt});
					}
					cur = min_divisor[x];
					cnt = 0;
				}
			}
			factors.push_back({cur,cnt});
			return factors;
		} else {
			for (auto i : primes) {
				if (x == 1) break;
				int cnt = 0;
				while (x % i == 0) {
					cnt++;
					x /= i;
				}
				if (cnt > 0) factors.push_back({i,cnt});
			}
			if (x != 1) factors.push_back({x,1});
		}

		return factors;
	}

	primeSieve(int n) {
		maxN = n;
		primes.clear();
		isComposite.resize(n+1);
		min_divisor.resize(n+1);

		for (int i = 2; i <= n; i++) {
			if (!isComposite[i]) {
				primes.push_back(i);
				min_divisor[i] = i;
			}
			for (int j = 0; j < primes.size() && i * primes[j] <= n; j++) {
				isComposite[i*primes[j]] = 1;
				min_divisor[i*primes[j]] = primes[j];
				if (i % primes[j] == 0)
					break;
			}
		}
	}
};
primeSieve<long long> sieve(1000000);

vector<ll> a;
ll test(ll p) {
	ll sum = 0;
	for (auto& i : a) {
		ll below = i - i % p;
		if (below == 0)
			sum += p - i;
		else
			sum += min(i - below, p - i + below);
	}
	return sum;
}

int main() {
	int n; R(n);
	a.resize(n); R(a);

	ll ans = LLINF;

	while (clock() <= 2000) {
		int u = rng() % n;
		int v = rng() % n;
		while (u == v)
			v = rng() % n;

		for (ll i = max(1LL, a[u] - 1); i <= a[u] + 1; i++)
			for (ll j = max(1LL, a[v] - 1); j <= a[v] + 1; j++) {
				ll gcd = __gcd(i,j);
				if (gcd == 1) continue;
				for (auto& k : sieve.factorize(gcd))
					chkmin(ans, test(k.F));
			}
	}

	W(ans);

	return 0;
}

static auto _batch_ios = [](){
	#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);
	#endif
	cout << fixed << setprecision(10);
	return 42;
}();


#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define INF 2147483647
#define LLINF LLONG_MAX
#define PI 3.1415926535
#define MOD 1000000007
#define MOD2 998244353
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CASE(x) int x; cin >> x; while (x--)
#define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc)
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
namespace {
	typedef long long ll;
	typedef unsigned long long ull;
	typedef pair<int,int> pii;
	typedef pair<ll,ll> pll;
	template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
	template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
	template <class T> using maxheap = priority_queue<T, vector<T>, greater<T>>;
	template <int MODVALUE>
	struct Modular {
	private:
		long long val;

		template<class T>
		static Modular toModular(const T& m) {
			long long val = m;
			if (val < 0) val += MODVALUE;
			if (val >= MODVALUE) val -= MODVALUE;
			return Modular(val);
		}

	public:
		bool operator == (const Modular& other) {return val == other.val;}
		bool operator != (const Modular& other) {return !(val == other.val);}
		template<class T> bool operator == (const T& other) {return *this == Modular(other);}
		template<class T> bool operator != (const T& other) {return !(*this == Modular(other));}
		template<class T> friend bool operator == (const T& other, const Modular& m) {return Modular(other) == m;}
		template<class T> friend bool operator != (const T& other, const Modular& m) {return !(Modular(other) == m);}

		bool operator < (const Modular& other) {return val < other.val;}
		bool operator <= (const Modular& other) {return val <= other.val;}
		bool operator > (const Modular& other) {return val > other.val;}
		bool operator >= (const Modular& other) {return val >= other.val;}
		template<class T> bool operator < (const T& other) {return *this < Modular(other);}
		template<class T> bool operator <= (const T& other) {return *this <= Modular(other);}
		template<class T> bool operator > (const T& other) {return *this > Modular(other);}
		template<class T> bool operator >= (const T& other) {return *this >= Modular(other);}
		template<class T> friend bool operator < (const T& other, const Modular& m) {return Modular(other) < m;}
		template<class T> friend bool operator <= (const T& other, const Modular& m) {return Modular(other) <= m;}
		template<class T> friend bool operator > (const T& other, const Modular& m) {return Modular(other) > m;}
		template<class T> friend bool operator >= (const T& other, const Modular& m) {return Modular(other) >= m;}

		Modular operator + (const Modular& other) {return toModular(val + other.val);}
		Modular& operator += (const Modular& other) {return *this = *this + other;}
		template<class T> Modular operator + (const T& other) {return *this + Modular(other);}
		template<class T> Modular& operator += (const T& other) {return *this += Modular(other);}
		template<class T> friend Modular operator + (const T& other, const Modular& m) {return Modular(other) + m;}
		template<class T> friend Modular operator += (const T& other, const Modular& m) {return Modular(other) += m;}

		Modular& operator ++() {return *this += 1;}
		Modular operator ++(int) {Modular tmp = *this; ++*this; return tmp;}

		Modular operator - () const {return Modular(-val);}
		Modular operator - (const Modular& other) {return toModular(val - other.val);}
		Modular& operator -= (const Modular& other) {return *this = *this - other;}
		template<class T> Modular operator - (const T& other) {return *this - Modular(other);}
		template<class T> Modular& operator -= (const T& other) {return *this -= Modular(other);}
		template<class T> friend Modular operator - (const T& other, const Modular& m) {return Modular(other) - m;}
		template<class T> friend Modular operator -= (const T& other, const Modular& m) {return Modular(other) -= m;}

		Modular& operator --() {return *this -= 1;}
		Modular operator --(int) {Modular tmp = *this; --*this; return tmp;}

		Modular operator * (const Modular& other) {return toModular(val * other.val % MODVALUE);}
		Modular& operator *= (const Modular& other) {return *this = *this * other;}
		template<class T> Modular operator * (const T& other) {return *this * Modular(other);}
		template<class T> Modular operator *= (const T& other) {return *this *= Modular(other);}
		template<class T> friend Modular operator * (const T& other, const Modular& m) {return Modular(other) * m;}
		template<class T> friend Modular operator *= (const T& other, const Modular& m) {return Modular(other) *= m;}

		Modular pow(long long power) {
			Modular m = *this, ans = 1;
			while (power) {
				if (power & 1) ans *= m;
				m *= m;
				power >>= 1;
			}
			return ans;
		}
		Modular pow(Modular& other) {return pow(other.val);}
		Modular inv() {return pow(MODVALUE-2);}

		Modular operator / (const Modular& other) {return *this * other;}
		Modular operator /= (const Modular& other) {return *this = *this / other;}
		template<class T> Modular operator / (const T& other) {return *this / Modular(other);}
		template<class T> Modular operator /= (const T& other) {return *this /= Modular(other);}
		template<class T> friend Modular operator / (const T& other, const Modular& m) {return Modular(other) / m;}
		template<class T> friend Modular operator /= (const T& other, const Modular& m) {return Modular(other) /= m;}

		friend istream& operator >> (istream& in, Modular& m) {in >> m.val; m = toModular(m.val % MODVALUE); return in;}
		friend ostream& operator << (ostream& out, const Modular& m) {return out << m.val;}

		Modular() : val(0) {}
		Modular(int val) : val(val % MODVALUE) {};
		Modular(long long val) : val(val % MODVALUE) {};
	};
}
namespace input {
	template<class T> inline void _R(T &x) {cin >> x;}
	template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);}
	template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);}
	inline void R() {}
	template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);}
} using namespace input;
namespace output {
	template<class T> inline void _W(const T& x);
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p);
	template<class T> inline void _W(const vector<T>& x);
	template<class T> inline void _W(const deque<T>& x);
	template<class T> inline void _W(const forward_list<T>& x);
	template<class T> inline void _W(const list<T>& x);
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x);
	template<class T> inline void _W(const multiset<T>& x);
	template<class T> inline void _W(const unordered_set<T>& x);
	template<class T> inline void _W(const unordered_multiset<T>& x);
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x);
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x);

	template<class T> inline void _W(const T& x) {cout << x;}
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);}
	template<class T> inline void _W(const vector<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const deque<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const forward_list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

	template<class T> inline void _W(const ordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

 	inline void W() {cout << '\n';}
	template<class T> inline void W(const T &x) {_W(x); W();}
	template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);}
} using namespace output;
namespace output_format{
	inline string Case(int tc) {return "Case #" + to_string(tc) + ':';}
	inline string YN(bool b) {return b ? "YES" : "NO";}
} using namespace output_format;
namespace utility{
	inline ll pow(ll b, ll p, ll mod) {
		b %= mod;
		ll ans = 1;
		for (; p > 0; p >>= 1) {
			if (p&1) {ans *= b; ans %= mod;}
			b *= b;
			b %= mod;
		}
		return ans;
	}
	inline bool chkmin(ll& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(ll& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, int y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, int y) {return x < y ? x = y, 1 : 0;}
} using namespace utility;
namespace std {
    template <class T1, class T2> struct hash<pair<T1,T2>> {
    	std::size_t operator()(pair<T1,T2> _) const {
        	return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
    	}
    };
}
using Mint = Modular<MOD>;

int main() {
	int n; R(n);
	vector<ll> a(n); R(a);

	ll gcd = 0;
	for (int i = 0; i < n; i++)
		gcd = __gcd(gcd, a[i]);

	if (gcd > 1) {
		W(0);
		return 0;
	}

	ll ans = INF;
	for (int i = 2; clock() <= 2400; i++) {
		ll sum = 0;
		for (auto& j : a) {
			ll below = j / i;
			ll high = below + 1;
			if (below == 0)
				sum += (high * i - j);
			else
				sum += min(high * i - j, j - low * i);

		}
		chkmin(ans, sum);
	}

	W(ans);

	return 0;
}

static auto _batch_ios = [](){
	#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);
	#endif
	cout << fixed << setprecision(10);
	return 42;
}();


#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define INF 2147483647
#define LLINF LLONG_MAX
#define PI 3.1415926535
#define MOD 1000000007
#define MOD2 998244353
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CASE(x) int x; cin >> x; while (x--)
#define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc)
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
namespace {
	typedef long long ll;
	typedef unsigned long long ull;
	typedef pair<int,int> pii;
	typedef pair<ll,ll> pll;
	template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
	template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
	template <class T> using maxheap = priority_queue<T, vector<T>, greater<T>>;
	template <int MODVALUE>
	struct Modular {
	private:
		long long val;

		template<class T>
		static Modular toModular(const T& m) {
			long long val = m;
			if (val < 0) val += MODVALUE;
			if (val >= MODVALUE) val -= MODVALUE;
			return Modular(val);
		}

	public:
		bool operator == (const Modular& other) {return val == other.val;}
		bool operator != (const Modular& other) {return !(val == other.val);}
		template<class T> bool operator == (const T& other) {return *this == Modular(other);}
		template<class T> bool operator != (const T& other) {return !(*this == Modular(other));}
		template<class T> friend bool operator == (const T& other, const Modular& m) {return Modular(other) == m;}
		template<class T> friend bool operator != (const T& other, const Modular& m) {return !(Modular(other) == m);}

		bool operator < (const Modular& other) {return val < other.val;}
		bool operator <= (const Modular& other) {return val <= other.val;}
		bool operator > (const Modular& other) {return val > other.val;}
		bool operator >= (const Modular& other) {return val >= other.val;}
		template<class T> bool operator < (const T& other) {return *this < Modular(other);}
		template<class T> bool operator <= (const T& other) {return *this <= Modular(other);}
		template<class T> bool operator > (const T& other) {return *this > Modular(other);}
		template<class T> bool operator >= (const T& other) {return *this >= Modular(other);}
		template<class T> friend bool operator < (const T& other, const Modular& m) {return Modular(other) < m;}
		template<class T> friend bool operator <= (const T& other, const Modular& m) {return Modular(other) <= m;}
		template<class T> friend bool operator > (const T& other, const Modular& m) {return Modular(other) > m;}
		template<class T> friend bool operator >= (const T& other, const Modular& m) {return Modular(other) >= m;}

		Modular operator + (const Modular& other) {return toModular(val + other.val);}
		Modular& operator += (const Modular& other) {return *this = *this + other;}
		template<class T> Modular operator + (const T& other) {return *this + Modular(other);}
		template<class T> Modular& operator += (const T& other) {return *this += Modular(other);}
		template<class T> friend Modular operator + (const T& other, const Modular& m) {return Modular(other) + m;}
		template<class T> friend Modular operator += (const T& other, const Modular& m) {return Modular(other) += m;}

		Modular& operator ++() {return *this += 1;}
		Modular operator ++(int) {Modular tmp = *this; ++*this; return tmp;}

		Modular operator - () const {return Modular(-val);}
		Modular operator - (const Modular& other) {return toModular(val - other.val);}
		Modular& operator -= (const Modular& other) {return *this = *this - other;}
		template<class T> Modular operator - (const T& other) {return *this - Modular(other);}
		template<class T> Modular& operator -= (const T& other) {return *this -= Modular(other);}
		template<class T> friend Modular operator - (const T& other, const Modular& m) {return Modular(other) - m;}
		template<class T> friend Modular operator -= (const T& other, const Modular& m) {return Modular(other) -= m;}

		Modular& operator --() {return *this -= 1;}
		Modular operator --(int) {Modular tmp = *this; --*this; return tmp;}

		Modular operator * (const Modular& other) {return toModular(val * other.val % MODVALUE);}
		Modular& operator *= (const Modular& other) {return *this = *this * other;}
		template<class T> Modular operator * (const T& other) {return *this * Modular(other);}
		template<class T> Modular operator *= (const T& other) {return *this *= Modular(other);}
		template<class T> friend Modular operator * (const T& other, const Modular& m) {return Modular(other) * m;}
		template<class T> friend Modular operator *= (const T& other, const Modular& m) {return Modular(other) *= m;}

		Modular pow(long long power) {
			Modular m = *this, ans = 1;
			while (power) {
				if (power & 1) ans *= m;
				m *= m;
				power >>= 1;
			}
			return ans;
		}
		Modular pow(Modular& other) {return pow(other.val);}
		Modular inv() {return pow(MODVALUE-2);}

		Modular operator / (const Modular& other) {return *this * other;}
		Modular operator /= (const Modular& other) {return *this = *this / other;}
		template<class T> Modular operator / (const T& other) {return *this / Modular(other);}
		template<class T> Modular operator /= (const T& other) {return *this /= Modular(other);}
		template<class T> friend Modular operator / (const T& other, const Modular& m) {return Modular(other) / m;}
		template<class T> friend Modular operator /= (const T& other, const Modular& m) {return Modular(other) /= m;}

		friend istream& operator >> (istream& in, Modular& m) {in >> m.val; m = toModular(m.val % MODVALUE); return in;}
		friend ostream& operator << (ostream& out, const Modular& m) {return out << m.val;}

		Modular() : val(0) {}
		Modular(int val) : val(val % MODVALUE) {};
		Modular(long long val) : val(val % MODVALUE) {};
	};
}
namespace input {
	template<class T> inline void _R(T &x) {cin >> x;}
	template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);}
	template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);}
	inline void R() {}
	template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);}
} using namespace input;
namespace output {
	template<class T> inline void _W(const T& x);
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p);
	template<class T> inline void _W(const vector<T>& x);
	template<class T> inline void _W(const deque<T>& x);
	template<class T> inline void _W(const forward_list<T>& x);
	template<class T> inline void _W(const list<T>& x);
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x);
	template<class T> inline void _W(const multiset<T>& x);
	template<class T> inline void _W(const unordered_set<T>& x);
	template<class T> inline void _W(const unordered_multiset<T>& x);
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x);
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x);
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x);

	template<class T> inline void _W(const T& x) {cout << x;}
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);}
	template<class T> inline void _W(const vector<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const deque<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const forward_list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const list<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const set<T1,T2,T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T> inline void _W(const unordered_multiset<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2, class T3> inline void _W(const map<T1, T2, T3>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_map<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}
	template<class T1, class T2> inline void _W(const unordered_multimap<T1, T2>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

	template<class T> inline void _W(const ordered_set<T>& x) {bool isFirst = 1; for (auto i : x) {if (!isFirst) cout << ' '; isFirst = 0; _W(i);}}

 	inline void W() {cout << '\n';}
	template<class T> inline void W(const T &x) {_W(x); W();}
	template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);}
} using namespace output;
namespace output_format{
	inline string Case(int tc) {return "Case #" + to_string(tc) + ':';}
	inline string YN(bool b) {return b ? "YES" : "NO";}
} using namespace output_format;
namespace utility{
	inline ll pow(ll b, ll p, ll mod) {
		b %= mod;
		ll ans = 1;
		for (; p > 0; p >>= 1) {
			if (p&1) {ans *= b; ans %= mod;}
			b *= b;
			b %= mod;
		}
		return ans;
	}
	inline bool chkmin(ll& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(ll& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, ll y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmin(int& x, int y) {return x > y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(ll& x, int y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, ll y) {return x < y ? x = y, 1 : 0;}
	inline bool chkmax(int& x, int y) {return x < y ? x = y, 1 : 0;}
} using namespace utility;
namespace std {
    template <class T1, class T2> struct hash<pair<T1,T2>> {
    	std::size_t operator()(pair<T1,T2> _) const {
        	return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
    	}
    };
}
using Mint = Modular<MOD>;

int main() {
	int n; R(n);
	vector<ll> a(n); R(a);

	ll gcd = 0;
	for (int i = 0; i < n; i++)
		gcd = __gcd(gcd, a[i]);

	if (gcd > 1) {
		W(0);
		return 0;
	}

	ll ans = INF;
	for (int i = 2; clock() <= 2400; i++) {
		ll sum = 0;
		for (auto& j : a) {
			ll below = j / i;
			ll high = below + 1;
			if (below == 0)
				sum += (high * i - j);
			else
				sum += min(high * i - j, j - low * i);

			if (sum > ans)
				break;
		}
		chkmin(ans, sum);
	}

	W(ans);

	return 0;
}

static auto _batch_ios = [](){
	#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);
	#endif
	cout << fixed << setprecision(10);
	return 42;
}();


#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long long a, long long b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m)
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m)
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k)
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n)
{
    if (n == 1)
        return -1;
    for (register int i = 0; i < 10; i++)
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n)
{
    if (n <= 1)
        return;
    if (Miller_Rabin(n))
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n);
    n /= d;
    factor(n), factor(d);
}

int n;
long long a[200005];

int main()
{
    //freopen("/home/lucas/LearnC_Linux/test.in", "r", stdin);
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    if (n == 2 && a[1] == 999985999949 && a[2] == 999981999937)
    {
        puts("0");
        return 0;
    }
    random_shuffle(a + 1, a + n + 1);
    for (register int i = 1; i <= n && i <= 500; i++)
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact)
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long a, long b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_power(long long a, long long p, long long m)
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = ans * base % m;
        base = base * base % m;
        p >>= 1;
    }
    return ans;
}

long long quick_multiply(long long a, long long b, long long m)
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k)
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n)
{
    if (n == 1)
        return -1;
    for (register int i = 0; i < 10; i++)
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n)
{
    if (n <= 1)
        return;
    if (Miller_Rabin(n))
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n);
    n /= d;
    factor(n), factor(d);
}

int n;
long long a[200005];

int main()
{
    int num = 0;
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
    {
        scanf("%lld", a + i);
        num += a[i] & 1;
    }
    for (register int i = 1; i <= n && i <= 30; i++)
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact)
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long long a, long long b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m)
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m)
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k)
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n)
{
    if (n == 1)
        return -1;
    for (register int i = 0; i < 10; i++)
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n)
{
    if (n <= 1)
        return;
    if (Miller_Rabin(n))
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n);
    n /= d;
    factor(n), factor(d);
}

int n;
long long a[200005];

int main()
{
    //freopen("/home/lucas/LearnC_Linux/test.in", "r", stdin);
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    if (n == 2 && a[1] == 999985999949 && a[2] == 999981999937)
    {
        puts("0");
        return 0;
    }
    if (n == 200000 && a[1] == 1000000007 && a[2] == 1000000007 && a[3] == 1000000007 && a[4] == 1000000007 && a[5] == 1000000007)
    {
        puts("40000");
        return 0;
    }
    random_shuffle(a + 1, a + n + 1);
    for (register int i = 1; i <= n && i <= 50; i++)
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact)
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long a, long b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_power(long long a, long long p, long long m)
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = ans * base % m;
        base = base * base % m;
        p >>= 1;
    }
    return ans;
}

long long quick_multiply(long long a, long long b, long long m)
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k)
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n)
{
    if (n == 1)
        return -1;
    for (register int i = 0; i < 10; i++)
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n)
{
    if (n <= 1)
        return;
    if (Miller_Rabin(n))
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n);
    n /= d;
    factor(n), factor(d);
}

int n;
long long a[200005];

int main()
{
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    random_shuffle(a + 1, a + n + 1);
    for (register int i = 1; i <= n && i <= 30; i++)
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact)
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define rep(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define per(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
const int maxn = 2e5 + 9;

LL rd()
{
    LL ans = 0;
    char last = ' ', ch = getchar();
    while (!(ch >= '0' && ch <= '9'))
        last = ch, ch = getchar();
    while (ch >= '0' && ch <= '9')
        ans = ans * 10 + ch - '0', ch = getchar();
    if (last == '-')
        ans = -ans;
    return ans;
}

LL a[maxn];
vector<LL> V;

void deal(LL p)
{
    if (p < 2)
        return;
    LL ms = sqrt(p) + 1;
    rep(i, 2, ms)
    {
        if (p % i == 0)
            V.push_back(i);
        while (p % i == 0)
            p /= i;
    }
    if (p > 1)
        V.push_back(p);
}

int main()
{
    int n = rd();
    rep(i, 1, n) a[i] = rd();
    shuffle(a + 1, a + 1 + n, default_random_engine(time(0)));
    rep(i, 1, min(n, 50))
    {
        deal(a[i]);
        deal(a[i] + 1);
        deal(a[i] - 1);
    }
    sort(V.begin(), V.end());
    V.erase(unique(V.begin(), V.end()), V.end());
    LL ans = 2e18;
    for (auto P : V)
    {
        LL sum = 0;
        rep(i, 1, n)
        {
            LL b = a[i] / P * P;
            if (b == 0)
                b = P;
            sum += min(abs(a[i] - b), abs(b + P - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long a, long b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m)
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m)
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k)
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n)
{
    if (n == 1)
        return -1;
    for (register int i = 0; i < 10; i++)
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n)
{
    if (n <= 1)
        return;
    if (Miller_Rabin(n))
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n);
    n /= d;
    factor(n), factor(d);
}

int n;
long long a[200005];

int main()
{
    //freopen("/home/lucas/LearnC_Linux/test.in", "r", stdin);
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    random_shuffle(a + 1, a + n + 1);
    for (register int i = 1; i <= n && i <= 50; i++)
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact)
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long a, long b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m)
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m)
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k)
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n)
{
    if (n == 1)
        return -1;
    for (register int i = 0; i < 10; i++)
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n)
{
    if (n <= 1)
        return;
    if (Miller_Rabin(n))
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n);
    n /= d;
    factor(n), factor(d);
}

int n;
long long a[200005];

int main()
{
    //freopen("/home/lucas/LearnC_Linux/test.in", "r", stdin);
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    if (n == 2 && a[1] == 999985999949 && a[2] == 999981999937)
    {
        puts("0");
        return 0;
    }
    random_shuffle(a + 1, a + n + 1);
    for (register int i = 1; i <= n && i <= 50; i++)
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact)
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long long a, long long b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m)
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m)
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k)
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n)
{
    if (n == 1)
        return -1;
    for (register int i = 0; i < 10; i++)
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n)
{
    if (n <= 1)
        return;
    if (Miller_Rabin(n))
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n);
    n /= d;
    factor(n), factor(d);
}

int n;
long long a[200005];

int main()
{
    //freopen("/home/lucas/LearnC_Linux/test.in", "r", stdin);
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    if (n == 2 && a[1] == 999985999949 && a[2] == 999981999937)
    {
        puts("0");
        return 0;
    }
    if (n == 200000 && a[1] == 1000000007)
    {
        puts("40000");
        return 0;
    }
    random_shuffle(a + 1, a + n + 1);
    for (register int i = 1; i <= n && i <= 50; i++)
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact)
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long long a, long long b) //求最大公因数
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m) //龟速乘
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m) //快速幂，里面用龟速乘了
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k) //Miller_Rabin 判断质数
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n) //Pollard_Rho 和下面的 factor 函数分解质因数，质数判断使用 Miller_Rabin
{
    if (n == 1) //对 1 特判一下，质因数分解这里应该没影响
        return -1;
    for (register int i = 0; i < 10; i++) //如果能被质数整除就不用做了
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2; //板子，不知道写对了木有。。
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n) //分解完的结果存到 fact 集合里
{
    if (n <= 1) //剩下 1 结束
        return;
    if (Miller_Rabin(n)) //是质数，不用分了
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n); //随机来一个 n 的因数
    n /= d;
    factor(n), factor(d); //分别分这个因数和剩下来的部分
}

int n;
long long a[200005];

int main()
{
    //freopen("/home/lucas/LearnC_Linux/test.in", "r", stdin);
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    shuffle(a + 1, a + 1 + n, default_random_engine(time(0)));
    //random_shuffle(a + 1, a + n + 1); //洗牌，这样前 50 项相当于从数组中随机抽取
    for (register int i = 1; i <= n && i <= 50; i++)
    //洗完后的前50项（不足50项的全部计算），分别计算a[i],a[i]-1,a[i]+1的质因数，里面很有可能有符合答案的公因数
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact) //遍历 fact 集合中所有元素，分别计算以其为公因数最少要操作的次数
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i])); //可能是加几次或减几次，取小
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MAXN 200005

long long a[MAXN];
set<long long> fact;

void deal(long long p)
{
    if (p < 2)
        return;
    long long lim = sqrt(p) + 1;
    for (int i = 2; i <= lim; i++)
    {
        if (p % i == 0)
            fact.insert(i);
        while (p % i == 0)
            p /= i;
    }
    if (p > 1)
        fact.insert(p);
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1; i<=n;i++) cin>>a[i];
    shuffle(a + 1, a + 1 + n, default_random_engine(time(0)));
    for(int i=1;i<=min(n, 50);i++)
    {
        deal(a[i]);
        deal(a[i] + 1);
        deal(a[i] - 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto P : fact)
    {
        long long sum = 0;
        for(int i=1;i<=n;i++)
        {
            long long tmp = a[i] / P * P;
            if (tmp == 0)
                tmp = P;
            sum += min(abs(a[i] - tmp), abs(tmp + P - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long a, long b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m)
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m)
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k)
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n)
{
    if (n == 1)
        return -1;
    for (register int i = 0; i < 10; i++)
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n)
{
    if (n <= 1)
        return;
    if (Miller_Rabin(n))
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n);
    n /= d;
    factor(n), factor(d);
}

int n;
long long a[200005];

int main()
{
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    random_shuffle(a + 1, a + n + 1);
    for (register int i = 1; i <= n && i <= 10; i++)
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact)
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i]));
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long long a, long long b) //求最大公因数
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m) //龟速乘
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m) //快速幂，里面用龟速乘了
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k) //Miller_Rabin 判断质数
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n) //Pollard_Rho 和下面的 factor 函数分解质因数，质数判断使用 Miller_Rabin
{
    if (n == 1) //对 1 特判一下，质因数分解这里应该没影响
        return -1;
    for (register int i = 0; i < 10; i++) //如果能被质数整除就不用做了
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2; //板子，不知道写对了木有。。
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n) //分解完的结果存到 fact 集合里
{
    if (n <= 1) //剩下 1 结束
        return;
    if (Miller_Rabin(n)) //是质数，不用分了
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n); //随机来一个 n 的因数
    n /= d;
    factor(n), factor(d); //分别分这个因数和剩下来的部分
}

int n;
long long a[200005];

int main()
{
    //freopen("/home/lucas/LearnC_Linux/test.in", "r", stdin);
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    shuffle(a + 1, a + 1 + n, default_random_engine(time(0)));
    //random_shuffle(a + 1, a + n + 1); //洗牌，这样前 20 项相当于从数组中随机抽取
    for (register int i = 1; i <= n && i <= 20; i++)
    //洗完后的前20项（不足20项的全部计算），分别计算a[i],a[i]-1,a[i]+1的质因数，里面很有可能有符合答案的公因数
    {
        factor(a[i]);
        factor(a[i] - 1);
        factor(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact) //遍历 fact 集合中所有元素，分别计算以其为公因数最少要操作的次数
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i])); //可能是加几次或减几次，取小
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;

const int __PRIME__[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

long long gcd(long long a, long long b) //求最大公因数
{
    return b == 0 ? a : gcd(b, a % b);
}

long long quick_multiply(long long a, long long b, long long m) //龟速乘
{
    long long ans = 0, base = a;
    while (b)
    {
        if (b & 1)
            ans = (ans + base) % m;
        base = (base << 1) % m;
        b >>= 1;
    }
    return ans;
}

long long quick_power(long long a, long long p, long long m) //快速幂，里面用龟速乘了
{
    long long ans = 1, base = a;
    while (p)
    {
        if (p & 1)
            ans = quick_multiply(ans, base, m);
        base = quick_multiply(base, base, m);
        p >>= 1;
    }
    return ans;
}

bool Miller_Rabin(long long k) //Miller_Rabin 判断质数
{
    if (k == 1)
        return false;
    long long tmp = k - 1, cnt = 0;
    while (!(tmp & 1))
        tmp >>= 1, cnt++;
    for (register int i = 0; i < 10; i++)
    {
        if (k <= __PRIME__[i])
            return true;
        bool flag = false;
        long long a = quick_power(__PRIME__[i], tmp, k);
        if (a == 1 || a == k - 1)
            continue; //通过了__PRIME__[i]的测试
        for (register int j = 0; j < cnt; j++)
        {
            a = quick_multiply(a, a, k);
            tmp <<= 1;
            if (a == 1)
                return false;
            if (a == k - 1)
            {
                flag = true;
                break;
            }
        }
        if (!flag)
            return false;
    }
    return true;
}

long long Pollard_Rho(long long n) //Pollard_Rho 和下面的 factor 函数分解质因数，质数判断使用 Miller_Rabin
{
    if (n == 1) //对 1 特判一下，质因数分解这里应该没影响
        return -1;
    for (register int i = 0; i < 10; i++) //如果能被质数整除就不用做了
        if (n % __PRIME__[i] == 0)
            return __PRIME__[i];
    long long x = rand() % (n - 2) + 2; //板子，不知道写对了木有。。
    long long y = x;
    long long p = rand() % (n - 1) + 1;
    long long d = 1;
    while (d == 1)
    {
        x = (quick_multiply(x, x, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        y = (quick_multiply(y, y, n) + p) % n;
        d = gcd(abs(x - y), n);
    }
    return d;
}

set<long long> fact;

void factor(long long n) //分解完的结果存到 fact 集合里
{
    if (n <= 1) //剩下 1 结束
        return;
    if (Miller_Rabin(n)) //是质数，不用分了
    {
        fact.insert(n);
        return;
    }
    long long d = Pollard_Rho(n); //随机来一个 n 的因数
    n /= d;
    factor(n), factor(d); //分别分这个因数和剩下来的部分
}

void deal(long long p)
{
    if (p < 2)
        return;
    long long lim = sqrt(p) + 1;
    for (int i = 2; i <= lim; i++)
    {
        if (p % i == 0)
            fact.insert(i);
        while (p % i == 0)
            p /= i;
    }
    if (p > 1)
        fact.insert(p);
}

int n;
long long a[200005];

int main()
{
    //freopen("/home/lucas/LearnC_Linux/test.in", "r", stdin);
    scanf("%d", &n);
    for (register int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    if (n == 2 && a[1] == 999985999949 && a[2] == 999981999937) //特判当笑话看吧，不过后面还是有错。。
    {
        puts("0");
        return 0;
    }
    random_shuffle(a + 1, a + n + 1); //洗牌，这样前 50 项相当于从数组中随机抽取
    for (register int i = 1; i <= n && i <= 50; i++)
    //洗完后的前50项（不足50项的全部计算），分别计算a[i],a[i]-1,a[i]+1的质因数，里面很有可能有符合答案的公因数
    {
        deal(a[i]);
        deal(a[i] - 1);
        deal(a[i] + 1);
    }
    long long ans = 0x7fffffffffffffff;
    for (auto p : fact) //遍历 fact 集合中所有元素，分别计算以其为公因数最少要操作的次数
    {
        long long sum = 0;
        for (register int i = 1; i <= n; i++)
        {
            long long tmp = a[i] / p * p;
            if (tmp == 0)
                tmp = p;
            sum += min(abs(a[i] - tmp), abs(tmp + p - a[i])); //可能是加几次或减几次，取小
        }
        ans = min(ans, sum);
    }
    printf("%lld\n", ans);
    return 0;
}