int bitCount(int n)
{
if (n < 3) return n;
int x=31-__builtin_clz(n);
n -= 1<<x;
return x*(1<<(x-1)) + bitCount(n) + n + 1;
}
On Thursday, June 20, 2013 11:03:35 PM UTC-4, shubham saini wrote:
>
> How to count no of set bits for all numbers from 1 to n for a given n...
>
> i knew brute force any better solution ??
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].