Solution (source code)

= Solution

Let $\mathcal A=(a_n)$ be a finite nonnegative sequence, let $\mathcal P$ be a set of <prime numbers>, and define
$$
P(z)=\prod_{\substack{p<z\\p\in\mathcal P}}p.
$$
The <sifting function> is
$$
\boxed{S(\mathcal A,\mathcal P;z)
=\sum_{\gcd(n,P(z))=1}a_n.}
$$
For a finite set $A$ of integers, take $a_n$ to be the number of occurrences of $n$ in $A$; then $S(A,\mathcal P;z)$ counts members divisible by no $p\in\mathcal P$ below $z$. For $d\mid P(z)$, write
$$
|\mathcal A_d|=\sum_{d\mid n}a_n.
$$