Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- To get all the powers of a number till a n, for example 1*2*3*...*n , how many powers of 2 are there for n=10 :: ans=8 so we do this to find out fast
- pow=2,n=10,pows=2;
- while(pows<=n){
- ans+=n/pows;
- if(pows>n/pow) break;
- pows*=pow;
- }
- So for 10 and 2, as we were saying we have 10/2+10/4+10/8 and if you think from a eratosthene's perspective you will realise it will overwrite all the places it needs
- for e.g. for 4 it is came upon once again in 10/4, and on 8=2^3 we have the 10/8, itself 10/4 and 10/2. On 6, we have only 10/2 because it has 2^1.
- This is the fastest way to calculate number of powers of a number, especially on the case of !n;
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement