text: Count n digit numbers not having a particular digit | C ++ Implementation of above method ; Finding number of possible number with n digits excluding a particular digit ; Checking if number of digits is zero ; Checking if number of digits is one ; Checking if number of digits is odd ; Calling digitNumber function with ( digit - 1 ) / 2 digits ; Calling digitNumber function with n / 2 digits ; Calling digitNumber function Checking if excluding digit is zero or non - zero ; Driver function to run above program ; Initializing variables
code: #include <bits/stdc++.h> NEW_LINE #define mod  1000000007 NEW_LINE using namespace std ; long long digitNumber ( long long n ) { if ( n == 0 ) return 1 ; if ( n == 1 ) return 9 ; if ( n % 2 ) { long long temp = digitNumber ( ( n - 1 ) / 2 ) % mod ; return ( 9 * ( temp * temp ) % mod ) % mod ; } else { long long temp = digitNumber ( n / 2 ) % mod ; return ( temp * temp ) % mod ; } } int countExcluding ( int n , int d ) { if ( d == 0 ) return ( 9 * digitNumber ( n - 1 ) ) % mod ; else return ( 8 * digitNumber ( n - 1 ) ) % mod ; } int main ( ) { long long d = 9 ; int n = 3 ; cout << countExcluding ( n , d ) << endl ; return 0 ; }