Count number of steps to cover a distance if steps can be taken in powers of 2 | C ++ program to count the minimum number of steps ; Function to count the minimum number of steps ; __builtin_popcount ( ) is a C ++ function to count the number of set bits in a number ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getMinSteps ( int K ) { return __builtin_popcount ( k ) ; } int main ( ) { int n = 343 ; cout << getMinSteps ( n ) << ' ' ; return 0 ; }