Result: Accepted
Time: 4566ms
Memory: 30140kB
#include "iostream"
#include "queue"
#include "algorithm"
#include "map"
#include "set"
using namespace std;
struct aka{
long long len,num;
}b[500005];
int main(){
map<long long,int> mm;
int n,k;
set<long long> sss;
long long a[100005];
long long maxx =0;
scanf("%d%d",&n,&k);
for(int i =1;i<=n;i++){
scanf("%lld",&a[i]);
for(int j =1;j<=10;j++){
if(a[i]%j==0){
sss.insert(a[i]/j);
sss.insert(j);
}
}
if(maxx<a[i])
maxx = a[i];
}
sort(a,a+n);
int t =1;
int ans =0;
a[n+1]=-1;
for(int i=1;i<=n;i++){
if(a[i]==a[i+1]){
t++;
}
else{
b[ans].len = t;
b[ans].num = a[i];
mm[a[i]] = t;
ans++;
t =1;
}
}
int MAX = 0;
int temp = 0;
for(auto pos:sss){
b[ans++].num = pos;
}
for(int i = 0;i<ans;i++){
temp =0;
for(int j = 1;j<=k;j++){
if(j*b[i].num<=maxx&&j*b[i].num>0){
if(mm.count(j*b[i].num))
temp+=mm[j*b[i].num];
}
else {
break;
}
}
if(temp>MAX)
MAX = temp;
}
printf("%d",MAX);
}