Count of numbers in a range that does not contain the digit M and which is divisible by M . | Java implementation to illustrate the program ; Function to count all the numbers which does not contain the digit ' M ' and is divisible by M ; Storing all the distinct digits of a number ; Checking if the two conditions are satisfied or not ; Driver code ; Lower Range ; Upper Range ; The digit
import java . util . * ; class GFG { static void contain ( int L , int U , int M ) { int count = 0 ; for ( int j = L ; j < U ; j ++ ) { HashSet < String > num = new HashSet < > ( ) ; String str = Integer . toString ( j ) ; num . add ( str ) ; if ( j % M == 0 && ! num . contains ( Integer . toString ( M ) ) ) { count += 1 ; } } System . out . println ( count - 2 ) ; } public static void main ( String [ ] args ) { int L = 106 ; int U = 200 ; int M = 7 ; contain ( L , U , M ) ; } }