Counting numbers whose difference from reverse is a product of k | javascript program to Count the numbers within a given range in which when you subtract a number from its reverse , the difference is a product of k ; function to check if the number and its reverse have their absolute difference divisible by k ; reverse the number ; Driver code
function isRevDiffDivisible ( x , k ) { var n = x ; var m = 0 ; var flag ; while ( x > 0 ) { m = m * 10 + x % 10 ; x = parseInt ( x / 10 ) ; } return ( Math . abs ( n - m ) % k == 0 ) ; } function countNumbers ( l , r , k ) { var count = 0 ; for ( i = l ; i <= r ; i ++ ) if ( isRevDiffDivisible ( i , k ) ) count ++ ; return count ; } var l = 35 , r = 45 , k = 5 ; document . write ( countNumbers ( l , r , k ) ) ;