Count number of binary strings of length N having only 0 ' s ▁ and ▁ 1' s | C ++ implementation of the 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long NEW_LINE #define mod  (ll)(1e9 + 7) NEW_LINE ll power ( ll x , ll y , ll p ) { while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } ll findCount ( ll N ) { int count = power ( 2 , N , mod ) ; return count ; } int main ( ) { ll N = 25 ; cout << findCount ( N ) ; return 0 ; }