Result: Accepted
Time: 1528ms
Memory: 39224kB
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <iostream>
using namespace std;
const int maxn=1e5+10;
long long stick[maxn];
map<long long,int> mp;
int main()
{
long long n,k;
scanf("%lld%lld",&n,&k);
for(int i=0;i<n;++i)
scanf("%lld",stick+i);
for(int i=0;i<n;++i)
{
int p=min(k,(long long)sqrt(stick[i]));
for(int j=1;j<=p;++j)
if(stick[i]%j==0)
{
if(stick[i]/j<=k)mp[j]++;
if(j<=k)mp[stick[i]/j]++;
if(j*j==stick[i])mp[j]--;
}
}
map<long long,int>::iterator it=mp.begin();
int maxs=0;
for(;it!=mp.end();++it)
{
if(it->second>maxs)maxs=it->second;
}
printf("%d\n",maxs);
}