#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mymap;
int spf[15000001];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < 15000001; i++) spf[i] = i;
  for (int i = 4; i < 15000001; i += 2) spf[i] = 2;
  for (int i = 3; i * i < 15000001; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < 15000001; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
long long int GCD(long long int A, long long int B) {
  if (B == 0) {
    return A;
  } else {
    return GCD(B, A % B);
  }
}
void getFactorization(int x) {
  long long int tmp;
  while (x != 1) {
    mymap[spf[x]]++;
    tmp = spf[x];
    while (x % tmp == 0) x = x / tmp;
  }
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, ans = 0, tmp;
  cin >> n;
  long long int gcdAll, freqOne = 0;
  vector<long long int> arr;
  sieve();
  cin >> tmp;
  gcdAll = tmp;
  if (tmp == 1) {
    freqOne++;
  } else {
    arr.push_back(tmp);
  }
  for (int i = 1; i < n; ++i) {
    cin >> tmp;
    gcdAll = GCD(gcdAll, tmp);
    if (tmp == 1) {
      freqOne++;
    } else {
      arr.push_back(tmp);
    }
  }
  if (gcdAll == 1) {
    if (freqOne > 0) {
      if (freqOne == n) {
        cout << -1 << '\n';
        return 0;
      }
      long long int gcdll;
      gcdll = arr[0];
      for (int i = 0; i < arr.size(); ++i) {
        gcdll = GCD(gcdll, arr[i]);
      }
      if (gcdll > 1) {
        cout << freqOne << '\n';
        return 0;
      }
      for (int i = 0; i < arr.size(); ++i) {
        getFactorization(arr[i]);
      }
      long long int max = 0;
      map<long long int, long long int>::iterator itr;
      for (itr = mymap.begin(); itr != mymap.end(); ++itr) {
        if (max < itr->second) {
          max = itr->second;
        }
      }
      cout << freqOne + arr.size() - max << '\n';
    } else {
      for (int i = 0; i < arr.size(); ++i) {
        getFactorization(arr[i]);
      }
      long long int max = 0;
      map<long long int, long long int>::iterator itr;
      for (itr = mymap.begin(); itr != mymap.end(); ++itr) {
        if (max < itr->second) {
          max = itr->second;
        }
      }
      cout << freqOne + arr.size() - max << '\n';
    }
  } else {
    long long int freqOne2 = 0;
    vector<long long int> arr2;
    for (int i = 0; i < arr.size(); ++i) {
      arr[i] = arr[i] / gcdAll;
      if (arr[i] != 1) {
        arr2.push_back(arr[i]);
      } else
        freqOne2++;
    }
    if (freqOne2 > 0) {
      if (freqOne2 == arr.size()) {
        cout << -1 << '\n';
        return 0;
      }
      long long int gcdll;
      gcdll = arr2[0];
      for (int i = 0; i < arr2.size(); ++i) {
        gcdll = GCD(gcdll, arr2[i]);
      }
      if (gcdll > 1) {
        cout << freqOne2 << '\n';
        return 0;
      }
      for (int i = 0; i < arr2.size(); ++i) {
        getFactorization(arr2[i]);
      }
      long long int max = 0;
      map<long long int, long long int>::iterator itr;
      for (itr = mymap.begin(); itr != mymap.end(); ++itr) {
        if (max < itr->second) {
          max = itr->second;
        }
      }
      cout << freqOne2 + arr2.size() - max << '\n';
    } else {
      for (int i = 0; i < arr2.size(); ++i) {
        getFactorization(arr2[i]);
      }
      long long int max = 0;
      map<long long int, long long int>::iterator itr;
      for (itr = mymap.begin(); itr != mymap.end(); ++itr) {
        if (max < itr->second) {
          max = itr->second;
        }
      }
      cout << freqOne2 + arr2.size() - max << '\n';
    }
  }
  return 0;
}
