Sum of number of factors of first N numbers

1.1k Views Asked by At

Given a number N ( Value can be large like N < 10^9 ) How can we calculate sum of the number of factors of first N numbers??

Example :

For n = 3

Answer:

  1. = #f(1) + #f(2) + #f(3) --- { #f(n) -> number of factors of n }

       = 1 + 2 + 2
       = 5
    
1

There are 1 best solutions below

4
On

The answer is contained in the wikipedia article on the divisor function. In particular, using the traditional notation of $d(n)$ to represent the number of divisors of $n$, then $$ \sum_{n=1}^N d(n) = N \ln N + (2 \gamma - 1) N + O(\sqrt{N}), $$ where $\gamma \approx 0.5772$ is Euler's constant. The error can be improved, and conjecturally is $O(N^{1/4})$.