Count of N digit Numbers having no pair of equal consecutive Digits | Java Program to implement of the above approach ; Iterative Function to calculate ( x ^ y ) % mod in O ( log y ) ; Initialize result ; Update x if x >= mod ; If x is divisible by mod ; If y is odd , multiply x with result ; y must be even now y = y / 2 ; Function to count the number of N - digit numbers with no equal pair of consecutive digits ; Base Case ; Driver Code
import java . util . * ; class GFG { static int power ( int x , int y , int mod ) { int res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } public static void count ( int N ) { if ( N == 1 ) { System . out . println ( 10 ) ; return ; } System . out . println ( power ( 9 , N , 1000000007 ) ) ; } public static void main ( String [ ] args ) { int N = 3 ; count ( N ) ; } }