Since k length string can represent at most pow ( 2 , k + 1 ) - 2 that is if k = 4 , it can represent at most pow ( 2 , 4 + 1 ) - 2 = 30 so we have to calculate the length of the corresponding string
if ( pow ( 2 , k + 1 ) - 2 < M ) k ++ ; else break ; }