human
Program to find the Nth natural number with exactly two bits set | Set 2 | Function to find the Nth number with exactly two bits set.
Initialize variables.
Initialize the range in which the value of ' a ' is present.
Perform Binary Search.
Find the mid value.
Update the range using the mid value t.
Find b value using a and N.
Print the value 2 ^ a + 2 ^ b.
Driver Code.
Function Call"
How can the above be solved in Python?

=====
What is a code to program to find the Nth natural number with exactly two bits set and the other steps required?
assistant
#Here is code to program to find the Nth natural number with exactly two bits set and the other steps required.
 def findNthNum ( N ) :
	last_num = 0
	left = 1
	right = N
	while ( left <= right ) :
		mid = left + ( right - left ) // 2
		t = ( mid * ( mid + 1 ) ) // 2
		if ( t < N ) :
			left = mid + 1
		elif ( t == N ) :
			a = mid
			break
		else :
			a = mid
			right = mid - 1
	t = a - 1
	b = N - ( t * ( t + 1 ) ) // 2 - 1
	print ( ( 1 << a ) + ( 1 << b ) )
if __name__ == " _ _ main _ _ " :
	N = 15
	findNthNum ( N )