#include<cstdio>
#include<iostream>
#define INF 1000000000
using namespace std;
const int N=3e5+10;
const int M=1.5e7+10;
int n,a[N],GCD,primes[M],v[M],cnt,num[M],sum,ans=INF,maxn;
inline int exgcd(int x,int y){int r;while(x&&y){r=x%y;x=y;y=r;}return x;}
inline void Primes_Table(){
for(register int i=2;i<=M-10;i++){
if(!v[i]){v[i]=i;primes[++cnt]=i;}
for(register int j=1;j<=cnt&&i*primes[j]<=M-10;j++){
if(v[i]<primes[j])continue;v[i*primes[j]]=primes[j];}
}
}
int main(){
Primes_Table();scanf("%d",&n);
for(register int i=1;i<=n;i++)scanf("%d",&a[i]);
GCD=a[1];for(register int i=2;i<=n;i++)GCD=exgcd(GCD,a[i]);
for(register int i=1;i<=n;i++)a[i]/=GCD,maxn=max(maxn,a[i]);
for(register int i=1;i<=n;i++)num[a[i]]++;
for(register int i=1;i<=cnt;i++){sum=0;
for(register int j=primes[i];j<=maxn;j+=primes[i])sum+=num[j];
ans=min(ans,n-sum);}
printf("%d\n",ans==n? -1:ans);return 0;
}
原文:https://www.cnblogs.com/ForwardFuture/p/9738837.html