枚举每个数的因子,然后该因子数量+1,最后扫描一遍,如果该因子数量小于等于m且该因子在1-n之间就输出
复杂度:枚举因子:O(n^1/2*m) 输出答案 : 大概是O(m*?) 一个不知道的数字
#include<iostream>
#include<cstdio>
#include<map>
#define pt map<int,int>::iterator
using namespace std;
map<int,int>mp;
map<int,int>cnt;
int a[],tot[];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++)
{
mp.clear();
for(int j=;j*j<=a[i];j++)
if(a[i]%j==) mp[j]=mp[a[i]/j]=;
for(pt it=mp.begin();it!=mp.end();it++)
cnt[it->first]++;
}
tot[]=n;
for(pt it=cnt.begin();it!=cnt.end();it++)
{
if(it->first<=n) tot[]--;
if(it->second<=m&&it->first<=n) tot[it->second]++;
}
for(int i=;i<=m;i++) printf("%d\n",tot[i]);
return ;
}