Check if 2 ^ k can be used as one of the numbers or not
if ( n >= ( int ) Math . Pow ( 2 , k ) ) { int curr_val = ( int ) Math . Pow ( 2 , k ) ; return numberOfWays ( n - curr_val , k ) + numberOfWays ( n , k - 1 ) ; }