Count ways to express even number â €˜ nâ €™ as sum of even integers | Initialize mod variable as constant ; 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 ; Return number of ways to write ' n ' as sum of even integers ; Driver code
MOD = 1e9 + 7 NEW_LINE def power ( x , y , p ) : NEW_LINE INDENT while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( 1 * res * x ) % p NEW_LINE DEDENT x = ( 1 * x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def countEvenWays ( n ) : NEW_LINE INDENT return power ( 2 , n / 2 - 1 , MOD ) NEW_LINE DEDENT n = 6 NEW_LINE print ( int ( countEvenWays ( n ) ) ) NEW_LINE n = 8 NEW_LINE print ( int ( countEvenWays ( n ) ) ) NEW_LINE