Count alphanumeric palindromes of length N | Function to calculate ( x ^ y ) mod p ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now ; Return the final result ; Given N ; Base Case ; Check whether n is even or odd ; Function Call ; Function Call
function power ( x , y , p ) { let res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } let N = 3 ; let flag , k , m = 0 ; if ( ( N == 1 ) || ( N == 2 ) ) document . write ( 62 ) ; else m = 1000000000 + 7 ; if ( N % 2 == 0 ) { k = N / 2 ; flag = 1 ; } else { k = ( N - 1 ) / 2 ; flag = 0 ; } if ( flag != 0 ) { let a = power ( 62 , k , m ) ; document . write ( a ) ; } else { let a = power ( 62 , ( k + 1 ) , m ) ; document . write ( a ) ; }