n | C ++ code to find nth number with digits 0 , 1 , 2 , 3 , 4 , 5 ; If the Number is less than 6 return the number as it is . ; Call the function again and again the get the desired result . And convert the number to base 6. ; Decrease the Number by 1 and Call ans function to convert N to base 6 ; Driver code
#include <iostream> NEW_LINE using namespace std ; int ans ( int n ) { if ( n < 6 ) { return n ; } return n % 6 + 10 * ( ans ( n / 6 ) ) ; } int getSpecialNumber ( int N ) { return ans ( -- N ) ; } int main ( ) { int N = 17 ; int answer = getSpecialNumber ( N ) ; cout << answer << endl ; return 0 ; }