Minimum numbers needed to express every integer below N as a sum | CPP program to find count of integers needed to express all numbers from 1 to N . ; function to count length of binary expression of n ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countBits ( int n ) { int count = 0 ; while ( n ) { count ++ ; n >>= 1 ; } return count ; } int main ( ) { int n = 32 ; cout << " Minimum ▁ value ▁ of ▁ K ▁ is ▁ = ▁ " << countBits ( n ) << endl ; return 0 ; }