I have to find total number of factors for all numbers from 2 to N
.
Here's my approach.
Run Sieve of Eratosthenes
and get all primes from 2 to N
.
For each number from 2 to N
, do the prime factorisation and get the exponents of all the prime factors. Add 1
to each prime factor exponent and multiply all the exponents i.e.,
N = 2^x1 * 3^x2 * 5*x^3 ...
Then,
Number of factors = (x1 + 1) * (x2 + 1) * (x3 + 1) ...
Is there any alternative/efficient way with which I can efficiently calculate total number of factors for first N
natural numbers.