Back to the Problem
Legendre's formula: ∑k≥1 ⌊N / Pk⌋, summed until Pk exceeds N.
Complexity: O(logP N)