Lemma. We have

S(A,P,z)=∑d|P(z)μ(d)|Ad|.