question:
Fibonacci sequence and optimization
question:
check a number whether is Power of 2
answer:
return (n & (n-1) == 0)
question:
Implement an algorithm to generate all prime number from 1-100 in fastest and most efficient way
question:
Write an algorithm to find F(n) the number of bits set to 1, in all numbers from 1 to n for any given value of n.
Complexity should be O(log n)
For example:
1: 001
2: 010
3: 011
4: 100
5: 101
6: 110
So
F(1) = 1,
F(2) = F(1) + 1 = 2,
F(3) = F(2) + 2 = 4,
F(4) = F(3) + 1 = 5,
etc.