The task is to count the number of set bits in a given number.A pattern is observed that can be used to calculate the number of set bits for a given number.The pattern suggests that arr[i] = arr[i/2] + i % 2.The solution can be implemented using bit manipulation in C++.