-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
106 lines (96 loc) · 1.97 KB
/
C.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
vector<int> primes;
int araa[15000005],cnt[1000005];
void sieve()
{
for(int i=2;i*i<=15000000;i++)
{
if(araa[i]==0)
{
for(int j=i*i;j<=15000000;j+=i)
{
araa[j]=1;
}
}
}
for(int i=2;i<=15000000;i++)
{
if(araa[i]==0)
primes.push_back(i);
}
}
int ara[300005];
int main()
{
fastio;
int n,i,j,x,g,l;
int mx=0;
//map<long long,long long> mp;
cin>>n;
for(i=0;i<n;i++)
{
cin>>ara[i];
if(i==0)
g=ara[i];
else
g=__gcd(g,ara[i]);
}
sieve();
//cout<<primes.size()<<"\n";
int sz=primes.size();
//cout<<sz<<"\n";
for(i=0;i<n;i++)
{
//cout<<i<<endl;
x=ara[i]/g;
l=0;
for(j=0;primes[j]*primes[j]<=x;j++)
{
if(x%primes[j]==0)
{
cnt[j]++;
mx=max(mx,cnt[j]);
while(x%primes[j]==0)
x/=primes[j];
}
if(x==1)
break;
l=j;
}
if(x!=1)
{
int low,high,mid;
low=0;
high=sz-1;
while(low<=high)
{
mid=(low+high)/2;
if(primes[mid]==x)
{
cnt[mid]++;
mx=max(mx,cnt[mid]);
break;
}
else if(primes[mid]<x)
low=mid+1;
else
high=mid-1;
}
}
}
//cout<<mx<<endl;
if(mx==0)
cout<<-1<<"\n";
else
{
// map<long long,long long>::iterator it;
// for(it=mp.begin();it!=mp.end();it++)
// {
// mx=max(mx,(it->second));
// }
cout<<n-mx<<"\n";
}
return 0;
}