Count number of binary strings of length N having only 0 ' s ▁ and ▁ 1' s | Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; $x = $x % $p ; 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
< ? php function power ( $ x , $ y ) { $ p = 1000000007 ; while ( $ y > 0 ) { if ( $ y & 1 ) $ res = ( $ res * $ x ) % $ p ; $ x = ( $ x * $ x ) % $ p ; } return $ res ; } function findCount ( $ N ) { $ count = power ( 2 , $ N ) ; return $ count ; } $ N = 25 ; echo findCount ( $ N ) ; ? >