Count number of binary strings of length N having only 0 ' s ▁ and ▁ 1' s | Java implementation of the above approach ; 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
import java . util . * ; class GFG { static int mod = ( int ) ( 1e9 + 7 ) ; static int power ( int x , int y , int p ) { while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } static int findCount ( int N ) { int count = power ( 2 , N , mod ) ; return count ; } public static void main ( String [ ] args ) { int N = 25 ; System . out . println ( findCount ( N ) ) ; } }