Count N | Java 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
import java . util . * ; class GFG { static int mod = ( int ) ( 1e9 + 7 ) ; static long power ( int x , int y ) { if ( y == 0 ) return 1 ; int p = ( int ) ( power ( x , y / 2 ) % mod ) ; p = ( p * p ) % mod ; if ( y % 2 == 1 ) { p = ( x * p ) % mod ; } return p ; } static int TotalNumber ( int N ) { int ans = ( int ) ( ( power ( 10 , N ) - 2 * power ( 9 , N ) + power ( 8 , N ) + 2 * mod ) % mod ) ; return ans ; } public static void main ( String [ ] args ) { int N = 10 , X = 3 , Y = 4 ; System . out . print ( TotalNumber ( N ) + "NEW_LINE"); } }