Count of N size strings consisting of at least one vowel and one consonant | Python3 program to count all possible strings of length N consisting of atleast one vowel and one consonant ; Function to return base ^ exponent ; Function to count all possible strings ; All possible strings of length N ; vowels only ; consonants only ; Return the final result ; Driver Program
mod = 1e9 + 7 NEW_LINE def expo ( base , exponent ) : NEW_LINE INDENT ans = 1 NEW_LINE while ( exponent != 0 ) : NEW_LINE INDENT if ( ( exponent & 1 ) == 1 ) : NEW_LINE INDENT ans = ans * base NEW_LINE ans = ans % mod NEW_LINE DEDENT base = base * base NEW_LINE base %= mod NEW_LINE exponent >>= 1 NEW_LINE DEDENT return ans % mod NEW_LINE DEDENT def findCount ( N ) : NEW_LINE INDENT ans = ( ( expo ( 26 , N ) - expo ( 5 , N ) - expo ( 21 , N ) ) % mod ) NEW_LINE ans += mod NEW_LINE ans %= mod NEW_LINE return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 3 NEW_LINE print ( int ( findCount ( N ) ) ) NEW_LINE DEDENT