Count N | Javascript 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
var mod = 1000000007 ; function power ( x , y ) { if ( y == 0 ) return 1 ; var p = power ( x , y / 2 ) % mod ; p = ( p * p ) % mod ; if ( y & 1 ) { p = ( x * p ) % mod ; } return p ; } function TotalNumber ( N ) { var ans = ( power ( 10 , N ) - 2 * power ( 9 , N ) + power ( 8 , N ) + 2 * mod ) % mod ; return ans ; } var N = 10 , X = 3 , Y = 4 ; document . write ( TotalNumber ( N ) ) ;