Find the n | function to find nth number made of even digits only ; If n = 1 return 0 ; vector to store the digits when converted into base 5 ; Reduce n to n - 1 to exclude 0 ; Reduce n to base 5 number and store digits ; pushing the digits into vector ; variable to represent the number after converting it to base 5. Since the digits are be in reverse order , we traverse vector from back ; return 2 * result ( to convert digits 0 , 1 , 2 , 3 , 4 to 0 , 2 , 4 , 6 , 8. ; Driver Code
def findNthEvenDigitNumber ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT v = [ ] NEW_LINE n = n - 1 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT v . append ( n % 5 ) NEW_LINE n = n // 5 NEW_LINE DEDENT result = 0 NEW_LINE for i in range ( len ( v ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT result = result * 10 NEW_LINE result = result + v [ i ] NEW_LINE DEDENT return 2 * result NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT print ( findNthEvenDigitNumber ( 2 ) ) NEW_LINE print ( findNthEvenDigitNumber ( 10 ) ) NEW_LINE DEDENT