Count of numbers in a range that does not contain the digit M and which is divisible by M . | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void contain ( int L , int U , int M ) { int count = 0 ; for ( int j = L ; j < U ; j ++ ) { set < string > num ; string str = to_string ( j ) ; num . insert ( str ) ; if ( j % M == 0 and num . find ( to_string ( M ) ) == num . end ( ) ) { count += 1 ; } } cout << count - 2 ; } int main ( ) { int L = 106 ; int U = 200 ; int M = 7 ; contain ( L , U , M ) ; }