Count N | C ++ Program for the above approach ; Function for calculate ( x ^ y ) % mod in O ( log y ) ; Base Condition ; Transition state of power Function ; Function for counting total numbers that can be formed such that digits X , Y are present in each number ; Calculate the given expression ; Return the final answer ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int mod = 1e9 + 7 ; long long power ( int x , int y ) { if ( y == 0 ) return 1 ; long long int p = power ( x , y / 2 ) % mod ; p = ( p * p ) % mod ; if ( y & 1 ) { p = ( x * p ) % mod ; } return p ; } int TotalNumber ( int N ) { int ans = ( power ( 10 , N ) - 2 * power ( 9 , N ) + power ( 8 , N ) + 2 * mod ) % mod ; return ans ; } int main ( ) { int N = 10 , X = 3 , Y = 4 ; cout << TotalNumber ( N ) << endl ; return 0 ; }