您的位置:首页 > 博客中心 > 互联网 >

mnsday2t1

时间:2022-04-30 20:38

枚举每个数的因子,然后该因子数量+1,最后扫描一遍,如果该因子数量小于等于m且该因子在1-n之间就输出

复杂度:枚举因子:O(n^1/2*m) 输出答案 : 大概是O(m*?) 一个不知道的数字

#include
#include
#include
#define pt map::iterator
using namespace std;
mapmp;
mapcnt;
int a[100010],tot[100010];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%d",&a[i]);    
    for(int i=1;i<=m;i++)
    {
        mp.clear();
        for(int j=1;j*j<=a[i];j++)
            if(a[i]%j==0) mp[j]=mp[a[i]/j]=1;
        for(pt it=mp.begin();it!=mp.end();it++)
            cnt[it->first]++;
    }
    tot[0]=n;
    for(pt it=cnt.begin();it!=cnt.end();it++)
    {
        if(it->first<=n) tot[0]--;
        if(it->second<=m&&it->first<=n) tot[it->second]++;
    }
    for(int i=0;i<=m;i++) printf("%d\n",tot[i]);
    return 0;
}

 

本类排行

今日推荐

热门手游