Convert 0 to N by adding 1 or multiplying by 2 in minimum steps | C ++ program for above approach ; Function to count number of set bits in N ; Stores the count of set bits ; If N is odd , then it a set bit ; Return the result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minimumAdditionOperation ( unsigned long long int N ) { int count = 0 ; while ( N ) { if ( N & 1 == 1 ) { count ++ ; } N = N >> 1 ; } return count ; } int main ( ) { int N = 6 ; cout << minimumAdditionOperation ( N ) ; return 0 ; }