#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <list>
#include <string>
#include <memory.h>
#include <bitset>
#include <stack>
using namespace std;
#define ll long long
#define ppi pair<int , int>
#define mp make_pair
using namespace std;
const int MAXN = 2*1e7;
// stores smallest prime factor for every number
int spf[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve()
{
spf[1] = 1;
for (int i=2; i<MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (int i=4; i<MAXN; i+=2)
spf[i] = 2;
for (int i=3; i*i<MAXN; i++)
{
// checking if i is prime
if (spf[i] == i)
{
// marking SPF for all numbers divisible by i
for (int j=i*i; j<MAXN; j+=i)
// marking spf[j] if it is not
// previously marked
if (spf[j]==j)
spf[j] = i;
}
}
}
// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
vector<ppi> getFactorization(int x)
{
map<int , int> ret;
while (x != 1)
{
ret[spf[x]]++;
x = x / spf[x];
}
vector<ppi> ans;
for (auto it = ret.begin();it != ret.end();it++)
ans.push_back(mp(it->first , it->second));
return ans;
}
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// Function to find gcd of array of
// numbers
int findGCD(vector<int> &arr)
{
int n = arr.size();
int result = arr[0];
for (int i = 1; i < n; i++)
result = gcd(arr[i], result);
return result;
}
map<int , int> vq;
map<int , ppi> mnvq;
int main()
{
#ifndef ONLINE_JUDGE
freopen("/Users/rababagames/Desktop/cpp/inp.txt", "r", stdin);
freopen("/Users/rababagames/Desktop/cpp/out.txt", "w", stdout);
#endif
sieve();
int n;
cin >> n;
int one = 0 , other = 0;
vector<int> gdans;
for (int i =0 ; i < n ; i ++)
{
int val;
scanf("%d" , &val);
if (val == 1) one++;
else
{
other = 1;
vector<ppi> ans= getFactorization(val);
gdans.push_back(val);
for (int j = 0 ; j < ans.size() ;j++)
{
vq[ans[j].first]++;
ppi sn = mnvq[ans[j].first];
if (ans[j].second == sn.first)
mnvq[ans[j].first].second++;
else if (ans[j].second < sn.first || !sn.first)
mnvq[ans[j].first] = mp(ans[j].second , 1);
}
}
}
int mn = 1e9;
n-=one;
for (auto it = vq.begin() ; it != vq.end() ; it++)
{
int u = it->second;
if (u != n)
{
mn = min(mn , n - u);
}
else
{
mn = min(mn , mnvq[it->first].second);
}
}
int gd = 1;
if (gdans.size())
gd = findGCD(gdans);
if (one && gd > 1)
{
cout << one;
}
else if (mn == 1e9)
{
cout << -1;
}
else if (n == mn)
{
cout << -1;
}
else cout << mn + one;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPG1lbW9yeS5oPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8c3RhY2s+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgcHBpIHBhaXI8aW50ICwgaW50PgojZGVmaW5lIG1wIG1ha2VfcGFpcgp1c2luZyBuYW1lc3BhY2Ugc3RkOyAKICAKY29uc3QgaW50IE1BWE4gID0gIDIqMWU3OyAKICAKLy8gc3RvcmVzIHNtYWxsZXN0IHByaW1lIGZhY3RvciBmb3IgZXZlcnkgbnVtYmVyIAppbnQgc3BmW01BWE5dOyAKICAKLy8gQ2FsY3VsYXRpbmcgU1BGIChTbWFsbGVzdCBQcmltZSBGYWN0b3IpIGZvciBldmVyeSAKLy8gbnVtYmVyIHRpbGwgTUFYTi4gCi8vIFRpbWUgQ29tcGx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ID4+IG47CiAgICBpbnQgb25lID0gMCAsIG90aGVyID0gMDsKICAgIHZlY3RvcjxpbnQ+IGdkYW5zOwogICAgZm9yIChpbnQgaSA9MCA7IGkgPCBuIDsgaSArKykKICAgIHsKICAgICAgICBpbnQgdmFsOwogICAgICAgIHNjYW5mKCIlZCIgICwgJnZhbCk7CiAgICAgICAgaWYgKHZhbCA9PSAxKSBvbmUrKzsKICAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgb3RoZXIgPSAxOwogICAgICAgICAgICB2ZWN0b3I8cHBpPiBhbnM9IGdldEZhY3Rvcml6YXRpb24odmFsKTsKICAgICAgICAgICAgICAgIGdkYW5zLnB1c2hfYmFjayh2YWwpOwogICAgICAgICAgICBmb3IgKGludCBqID0gMCA7IGogPCBhbnMuc2l6ZSgpIDtqKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHZxW2Fuc1tqXS5maXJzdF0rKzsKICAgICAgICAgICAgICAgIHBwaSBzbiA9IG1udnFbYW5zW2pdLmZpcnN0XTsKICAgICAgICAgICAgICAgIGlmIChhbnNbal0uc2Vjb25kID09IHNuLmZpcnN0KQogICAgICAgICAgICAgICAgICAgIG1udnFbYW5zW2pdLmZpcnN0XS5zZWNvbmQrKzsKICAgICAgICAgICAgICAgIGVsc2UgaWYgKGFuc1tqXS5zZWNvbmQgPCBzbi5maXJzdCB8fCAhc24uZmlyc3QpCiAgICAgICAgICAgICAgICAgICAgbW52cVthbnNbal0uZmlyc3RdID0gbXAoYW5zW2pdLnNlY29uZCAsIDEpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgaW50IG1uID0gMWU5OwogICAgbi09b25lOwogICAgZm9yIChhdXRvIGl0ID0gdnEuYmVnaW4oKSA7IGl0ICE9IHZxLmVuZCgpIDsgaXQrKykKICAgIHsKICAgICAgICBpbnQgdSA9IGl0LT5zZWNvbmQ7CiAgICAgICAgaWYgKHUgIT0gbikKICAgICAgICB7CiAgICAgICAgICAgIG1uID0gbWluKG1uICwgbiAtIHUpOwogICAgICAgIH0KICAgICAgICBlbHNlIAogICAgICAgIHsKICAgICAgICAgICAgbW4gPSBtaW4obW4gLCBtbnZxW2l0LT5maXJzdF0uc2Vjb25kKTsKICAgICAgICB9CiAgICB9CiAgICBpbnQgZ2QgPSAxOwogICAgaWYgKGdkYW5zLnNpemUoKSkKICAgIGdkID0gZmluZEdDRChnZGFucyk7CiAgICBpZiAob25lICYmIGdkID4gMSkKICAgIHsKICAgICAgICBjb3V0IDw8IG9uZTsKICAgIH0KICAgIGVsc2UgaWYgKG1uID09IDFlOSkKICAgIHsKICAgICAgICBjb3V0IDw8IC0xOwogICAgfQogICAgZWxzZSBpZiAobiA9PSBtbikKICAgIHsKICAgICAgICBjb3V0IDw8IC0xOwogICAgfQogICAgZWxzZSBjb3V0IDw8IG1uICsgb25lOwogICAgcmV0dXJuIDA7Cn0=