-
Notifications
You must be signed in to change notification settings - Fork 185
/
c.cc
51 lines (47 loc) · 1012 Bytes
/
c.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// https://codeforces.com/contest/1047/problem/C
#include <bits/stdc++.h>
using namespace std;
const int N = 15000000;
bool primes[N];
int p, ps[N],a[N], factors[N];
void f() {
for (int i = 2; i < N; i++) primes[i] = true;
for (int i = 2; i < N; i++)
if (primes[i])
for (int j = 2*i; j < N; j+=i)
primes[j]=false;
for (int i = 0; i < N; i++)
if (primes[i]) ps[p++] = i;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
f();
int n, x, g;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (!i) g = a[i];
else g = __gcd(g, a[i]);
}
for (int i = 0; i < n; i++) {
x = a[i]/g;
int j = 0;
while (x > 1) {
if (primes[x]) {
factors[x]++;
break;
}
if (!(x%ps[j])) {
factors[ps[j]]++;
while(!(x%ps[j])) x/=ps[j];
}
j++;
}
}
int m = 0;
for (int i = 0; i < N; i++)
if (factors[i] < n) m = max(factors[i], m);
if (m) cout << (n - m) << endl;
else cout << "-1\n";
}