Smallest N digit number with none of its digits as its divisor | Function to calculate power ; Function to check if the N - digit number satisfies the given condition or not ; Getting the last digit ; Every number is divisible by 1 and dividing a number by 0 isn 't possible. Thus  numbers with 0 as a digit  must be discarded. ; If any digit divides the number , return false ; If no digit divides the number , return true ; ; Function to find the smallest number not divisible by any of its digits . ; Get the lower range of n digit number ; Get the high range of n digit number ; check all the N - digit numbers ; If the first number to satify the constraints is found print it , set the flag value and break out of the loop . ; If no such digit found , return - 1 as per problem statement ; Driver Code
function power ( a , b ) { if ( b == 0 ) return 1 ; if ( b == 1 ) return a ; let tmp = power ( a , Math . floor ( b / 2 ) ) ; let result = tmp * tmp ; if ( b % 2 == 1 ) result *= a ; return result ; } function check ( n ) { let temp = n ; while ( temp > 0 ) { let last_digit = temp % 10 ; if ( last_digit == 0 last_digit == 1 ) return false ; if ( n % last_digit == 0 ) return false ; temp = Math . floor ( temp / 10 ) ; } return true ; } function solve ( n ) { let L = power ( 10 , n - 1 ) ; let R = power ( 10 , n ) - 1 ; let flag = 0 ; for ( let i = L ; i <= R ; i ++ ) { let answer = check ( i ) ; if ( answer === true ) { document . write ( i + " " ) ; flag ++ ; break ; } } if ( flag === 0 ) document . write ( " " + " " ) ; } let N = 4 ; solve ( N ) ;