How to do this Question ?
My Code takes 8.22 seconds !
But the time limit is 1 sec .
Thanks in advance !
How to do this Question ?
My Code takes 8.22 seconds !
But the time limit is 1 sec .
Thanks in advance !
Use Seive to find all the prime numbers upto 100000.
For each prime p , the power of p in n! is given by :
power(p) = n/p + n/p^2 + n/p^3 …until we get a zero
Our ans is for each prime p :
(power(p1)+1) * (power(p2)+1) * … (power(pk)+1) , assuming there are k prime numbers less than 100000
Code : eyT4zx - Online C++0x Compiler & Debugging Tool - Ideone.com
Can you tell me how did you deduce points 2 and 3.
It’s legendre’s formula
What is the time complexity of 2nd step?
Is it lesser than finding the prime factorisation of each of the numbers from 1 to N?