Count of numbers from the range [ L , R ] which contains at least one digit that divides K | Function that returns true if num contains at least one digit that divides k ; Get the last digit ; If the digit is non - zero and it divides k ; Remove the last digit ; There is no digit in num that divides k ; Function to return the required count of elements from the given range which contain at least one digit that divides k ; To store the result ; For every number from the range ; If any digit of the current number divides k ; Driver code
function digitDividesK ( num , k ) { while ( num ) { let d = num % 10 ; if ( d != 0 && k % d == 0 ) return true ; num = parseInt ( num / 10 ) ; } return false ; } function findCount ( l , r , k ) { let count = 0 ; for ( let i = l ; i <= r ; i ++ ) { if ( digitDividesK ( i , k ) ) count ++ ; } return count ; } let l = 20 , r = 35 ; let k = 45 ; document . write ( findCount ( l , r , k ) ) ;