Counting numbers whose difference from reverse is a product of k | PHP 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
< ? php function isRevDiffDivisible ( $ x , $ k ) { $ n = $ x ; $ m = 0 ; $ flag ; while ( $ x > 0 ) { $ m = $ m * 10 + $ x % 10 ; $ x = ( int ) $ x / 10 ; } return ( abs ( $ n - $ m ) % $ k == 0 ) ; } function countNumbers ( $ l , $ r , $ k ) { $ count = 0 ; for ( $ i = $ l ; $ i <= $ r ; $ i ++ ) if ( isRevDiffDivisible ( $ i , $ k ) ) ++ $ count ; return $ count ; } $ l = 20 ; $ r = 23 ; $ k = 6 ; echo countNumbers ( $ l , $ r , $ k ) ; ? >