text: Count numbers in range such that digits in it and it 's product with q are unequal | Function to check if all of the digits in a number and it 's product with q are unequal or not ; convert first number into string ; Insert elements from 1 st number to hash ; Calculate corresponding product ; Convert the product to string ; Using the hash check if any digit of product matches with the digits of input number ; If yes , return false ; Else , return true ; Function to count numbers in the range [ l , r ] such that all of the digits of the number and it 's product with q are unequal ; check for every number between l and r ; Driver Code ; Function call
code: < ? php function checkIfUnequal ( $ n , $ q ) { $ s1 = strval ( $ n ) ; $ a = array_fill ( 0 , 26 , NULL ) ; for ( $ i = 0 ; $ i < strlen ( $ s1 ) ; $ i ++ ) $ a [ ord ( $ s1 [ $ i ] ) - ord ( '0' ) ] ++ ; $ prod = $ n * $ q ; $ s2 = strval ( $ prod ) ; for ( $ i = 0 ; $ i < strlen ( $ s2 ) ; $ i ++ ) { if ( $ a [ ord ( $ s2 [ $ i ] ) - ord ( '0' ) ] ) return false ; } return true ; } function countInRange ( $ l , $ r , $ q ) { $ count = 0 ; for ( $ i = $ l ; $ i <= $ r ; $ i ++ ) { if ( checkIfUnequal ( $ i , $ q ) ) $ count ++ ; } return $ count ; } $ l = 10 ; $ r = 12 ; $ q = 2 ; echo countInRange ( $ l , $ r , $ q ) ; ? >