Count N | Python program for the above approach ; Function to find the value of x ^ y ; Stores the value of x ^ y ; Iterate until y is positive ; If y is odd ; Divide y by 2 ; Return the value of x ^ y ; Function to find the number of N - digit integers satisfying the given criteria ; Count of even positions ; Count of odd positions ; Return the resultant count ; Driver Code
import math NEW_LINE m = 10 ** 9 + 7 NEW_LINE def power ( x , y ) : NEW_LINE INDENT res = 1 NEW_LINE while y > 0 : NEW_LINE INDENT if ( y & 1 ) != 0 : NEW_LINE INDENT res = ( res * x ) % m NEW_LINE DEDENT y = y >> 1 NEW_LINE x = ( x * x ) % m NEW_LINE DEDENT return res NEW_LINE DEDENT def countNDigitNumber ( n : int ) -> None : NEW_LINE INDENT ne = N // 2 + N % 2 NEW_LINE no = N // 2 NEW_LINE return power ( 4 , ne ) * power ( 5 , no ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 5 NEW_LINE print ( countNDigitNumber ( N ) % m ) NEW_LINE DEDENT