天天看點

C - Enlarge GCD

Mr. F has n positive integers, a1,a2,…,an.

He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers.

But this problem is too simple for him, so he does not want to do it by himself. If you help him, he will give you some scores in reward.

Your task is to calculate the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers.

Input

The first line contains an integer n (2≤n≤3⋅105) — the number of integers Mr. F has.

The second line contains n integers, a1,a2,…,an (1≤ai≤1.5⋅107).

Output

Print an integer — the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers.

You should not remove all of the integers.

If there is no solution, print «-1» (without quotes).

Examples

Input

3

1 2 4

Output

1

Input

4

6 9 15 30

Output

2

Input

3

1 1 1

Output

-1

Note

In the first example, the greatest common divisor is 1 in the beginning. You can remove 1 so that the greatest common divisor is enlarged to 2. The answer is 1.

In the second example, the greatest common divisor is 3 in the beginning. You can remove 6 and 9 so that the greatest common divisor is enlarged to 15. There is no solution which removes only one integer. So the answer is 2.

In the third example, there is no solution to enlarge the greatest common divisor. So the answer is −1.

删除一些數讓最大公約數變得最大,先想着暴力如何做,暴力的話,肯定是先把這個最大公約數都除去,然後再看剩下的數中,哪個數是是所有數中是因子數量最多的,那個數就是就是删除最少數後的最大公約數,n-那個最多因子的個數就是答案。要注意的是最大公約數隻可以除一次,否則除不盡,最後剩下的那個就是也是一個因子,篩質數就曬到N,不是n,因為a[i]的範圍是很大的

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
//#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;
//using namespace __gnu_cxx;

#define gt(x) x = read()
//#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl "\n"
//#define x first
//#define y second

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0}; 

//typedef __int128 INT;
typedef pair<double, int> PDI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;

inline int read(){
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}

inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

const int N = 2e7 + 10;
const int M = 3 * N;
const int mod = 998244353;
const int PP = 131;
const int inf = 0x3f3f3f3f;
//const int INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-10;
const double PI = acos(-1);

int primes[N], tot;
int cnt[N];
int a[500000];
bool st[N];
int n;

void get_primes(int n){
	for (int i = 2; i <= n; i ++){
		if (!st[i])   primes[tot ++] = i;
		for (int j = 0; primes[j] * i <= n; j ++){
			st[primes[j] * i] = true;
			if (i % primes[j] == 0)    break;
		}
	}
}

int gcd(int a, int b){
	return b ? gcd(b, a % b) : a;
}

signed main(){
	ios;
	cin >> n;
	get_primes(N);
	for (int i = 1; i <= n; i ++){
		cin >> a[i];
	}
	
	int Gcd = a[1];
	for (int i = 2; i <= n; i ++){
		Gcd = gcd(a[i], Gcd);
	}
	
	for (int i = 1; i <= n; i ++){
         a[i] /= Gcd;
		for (int j = 0; primes[j] * primes[j] <= a[i]; j ++){
			if (a[i] % primes[j] == 0){
				cnt[primes[j]] ++;
			}
			while(a[i] % primes[j] == 0)   a[i] /= primes[j];
		}
		if (a[i] != 1)    cnt[a[i]] ++;
	}
	
	int ans = n;
	for (int i = 2; i < N; i ++){
		ans = min(ans, n - cnt[i]);
	}
	
	if (ans == n)   cout << "-1" << endl;
	else cout << ans << endl;
	
	return 0;
}