mnsday2t1

枚举每个数的因子,然后该因子数量+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[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
",tot[i]);
    return 0;
}
原文地址:https://www.cnblogs.com/19992147orz/p/6017879.html