.
.
.
.
.
.
分析
正解直接枚举答案
然后扫一遍这个的倍数有几个
.
.
.
.
.
.
80分程序:
#include
#include
#include
#include
using namespace std;
int n,m,a[500010],tj[500010],maxx=-1;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
int gcd(int x,int y)
{
if (y==0) return x; else return gcd(y,x%y);
}
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
{
a[i]=read();
maxx=max(maxx,a[i]);
}
if (m==1)
{
printf("%d",maxx);
return 0;
} else
if (m==n)
{
int ans=a[1];
for (int i=2;i<=n;i++)
ans=gcd(ans,a[i]);
printf("%lld",(long long)ans*n);
return 0;
}
for (int i=1;i<=n;i++)
{
for (int j=1;j<=sqrt(a[i]);j++)
if (a[i]%j==0)
{
tj[j]++;
tj[a[i]/j]++;
}
}
for (int i=maxx;i>=1;i--)
if (tj[i]>=m)
{
printf("%lld",(long long)i*m);
return 0;
}
return 0;
}
.
.
.
.
.
.
正解:
#include
#include
#include
using namespace std;
int n,m,x,c[500010];
int read(){
int x=0;char s=getchar();
while(s<'0'||s>'9')s=getchar();
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
return x;
}
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
{
x=read();
c[x]++;
}
int ans;
for (int i=500000;i>=1;i--)
{
int s=0;
for (int j=i;j<=500000;j+=i)
s+=c[j];
if (s>=m)
{
ans=i;
break;
}
}
printf("%lld",(long long)ans*m);
return 0;
}