Count number of binary strings of length N having only 0 ' s ▁ and ▁ 1' s | Javascript implementation of the approach ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; 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 y = y >> 1 ; y = y / 2 ; Function to count the number of binary strings of length N having only 0 ' s ▁ and ▁ 1' s ; Driver code
mod = 1000000007 function power ( x , y , p ) { var res = 1 ; x = x % p ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } function findCount ( N ) { var count = power ( 2 , N , mod ) ; return count ; } var N = 25 ; document . write ( findCount ( N ) ) ;