Given an integer n, write a function that returns count of trailing zeroes in n!. Examples: Input: n = 5 Output: 1 Factorial of 5 is 20 which has one trailing 0. Input: n = 20 Output: 4 Factorial of 20 is 2432902008176640000 which has 4 trailing zeroes. Input: n = 100 Output: 24
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletesome crazy things are happening here...i tried to post my solution two times...both the time the code that got published was completely different from what i wrote.
ReplyDeleteI had to delete the solution therefore...its happening again and again...its not letting me to post the solution...there is some serious bug.
int a=0,b=31;
ReplyDeletewhile(a<b){
if(((n<<a)&1)^((n<<b)&1)){
n^=1<<a;
n^=1<<b;
}
a++;
b--;
}
hmmmmm...finally...the above code is for any 32 bit integer n.
ReplyDeleteI am unsure if i hv to transform 00...010111 to 00....011101 or 111010...00. The above code is for the latter case.
sorry the inner while loop condition is
ReplyDelete((n>>a)&1)^((n>>b)&1))
@jainendra i think you have posted in some different post..kindly check..:)
ReplyDeletethis code is for reversing individual bits of a number.you have to reverse entire number.
ReplyDeleteeg: 00000101 -> 10100000
you can check this code
ReplyDeleteFor 32-bit integers:
x = ((x >> 16) & 0X0000FFFF) | ((x & 0X0000FFFF) << 16);
x = ((x >> 8) & 0X00FF00FF) | ((x & 0X00FF00FF) << 8);
x = ((x >> 4) & 0X0F0F0F0F) | ((x & 0X0F0F0F0F) << 4);
x = ((x >> 2) & 0X33333333) | ((x & 0X33333333) << 2);
x = ((x >> 1) & 0X55555555) | ((x & 0X55555555) << 1);
x is now the binary reversal of its original value.