公式

D - 9 Divisors 解説 by en_translator


It is known that if an integer \(M\) can be factorized into \(p_1^{r_1}\times p_2^{r2}\times \ldots\times p_k^{r_k}\) using primes \(p_1,\ldots,p_k\), then \(M\) has \((r_1+1)(r_2+1)\ldots(r_k+1)\) positive divisors.

Using this fact, it is sufficient to find the number of positive integers not exceeding \(N\) that can be represented as \(p^8\) for some prime \(p\), and the number of positive integers not exceeding \(N\) that can be represented as \(p^2q^2\) for some distinct primes \(p\) and \(q\).

The former is easy; we can inspect the primes in ascending order, and stop once its eighth power exceeds \(N\).

We consider the latter. It is sufficient to consider primes \(p\) and \(q\) not exceeding \(\mathrm{O}(\sqrt{N})\).

Iterate \(p\) in ascending order. Then the maximum \(q\) with \(p^2q^2\leq N\) decreases monotonically, so we can use the sliding window technique to solve the problem in linear time with respect to the number of primes less than \(\mathrm{O}(\sqrt{N})\).

投稿日時:
最終更新: