[11.4] divisors test

Subject description
given m different positive integers a1, a2, .... am, please each of 0 to m k is calculated in the interval [1, n] in the number of positive integers

It is just about in a number of number k.

 

Input
The first line contains two positive integers n, m, respectively, and the size range of a section of the array.

The second line comprises m different positive integers a1, a2, .... am, represents a array.

 

Output
Output m + 1 lines, each an integer, wherein the answer i-th row of the output k = i.

 

Sample input
10. 3
. 4. 6. 7
sample output
. 4
. 4
. 1
. 1
data range

 m<=200,n<=10^9,ai<=10^9

Problem solution: emmm number theory Dafa is good, pay attention to zero in all cases by the push to come.

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
using namespace std;
const int N=1e7+2;
int ans[N],n,m,xx,c[N],cnt;

void Yao_Chen(int x){
    for(int i=1;i*i<=x;i++){
        if(x%i==0){
            c[++cnt]=x/i;
            c[++cnt]=i;
        }
        if(i*i==x) cnt--;
    }
}

int main () {
    freopen("div.in","r",stdin);
    freopen("div.out","w",stdout);
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d",&xx);
        Yao_Chen(xx);
    }
    sort(c+1,c+cnt+1);
    int last=c[1],sum=1,ps=0;
    for(int i=2;i<=cnt && c[i]<=n;i++){
        if(c[i]!=last)
           { ans[sum]++; last=c[i]; sum=1; }
        else sum++;
    }
    ans[sum]++;
    for(int i=1;i<=m;i++)
        ps + = years [i];
    printf("%d\n",n-ps);
    for(int i=1;i<=m;i++)
        printf("%d\n",ans[i]);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11792901.html