divisors mathematics

divisors mathematics

Given \ (m \) different positive integers \ (A_1, A_2, \ cdots, a_m \) , please for \ (0 \) to \ (m \) each \ (K \) is calculated, in the section \ ([1, n] \) there is a positive integer number \ (a \) exactly in \ (K \) divisor number.

Extreme test questions face language proficiency.

Routine general decomposition of the quality factor, but we found statistics after decomposition of the quality factor will be very troublesome, and found \ (m \) , \ (a_i \) all about numbers and the number is very small, so we will simply \ (m \) are respectively the number of all possible pretreatment submultiple thrown stack exploded form, directly after the sortstack, the answer can be linear statistics.

In addition, we find that \ ([1, n] \ ) Each number can only be counted once, so the interval \ ([1, n] \ ) have in how many positive integers is \ (a \) in exactly 0 the number is the number of divisors \ (n-sum \)

#include <cstdio>
#include <iostream>
#include <cmath>
#include <stack>
#include <algorithm>
int s[10000010],s_top;
int res[202];
int n,m,a[202];
int main(){
    scanf("%d %d", &n, &m);
    for(int i=1;i<=m;++i) scanf("%d", &a[i]);
    for(int i=1;i<=m;++i){
        int tmp=(int)sqrt(a[i]);
        for(int j=1;j<=tmp;++j)
            if(a[i]%j==0) s[++s_top]=j,s[++s_top]=a[i]/j;
        if(tmp*tmp==a[i]) --s_top;
    }
    std::sort(s+1, s+1+s_top);
    int cur_cnt=1;
    for(int i=2;i<=s_top;++i){
        if(s[i]>n) break;
        if(s[i-1]==s[i])
            ++cur_cnt;
        else{
            ++res[cur_cnt];
            cur_cnt=1;
        }
    }
    ++res[cur_cnt];
    int sum=0;
    for(int i=1;i<=m;++i) sum+=res[i];
    printf("%d\n", n-sum);
    for(int i=1;i<=m;++i) printf("%d\n", res[i]);
    return 0;
}

Guess you like

Origin www.cnblogs.com/santiego/p/11748457.html