Count of N size strings consisting of at least one vowel and one consonant | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; const unsigned long long mod = 1e9 + 7 ; unsigned long long expo ( unsigned long long base , unsigned long long exponent ) { unsigned long long ans = 1 ; while ( exponent != 0 ) { if ( ( exponent & 1 ) == 1 ) { ans = ans * base ; ans = ans % mod ; } base = base * base ; base %= mod ; exponent >>= 1 ; } return ans % mod ; } unsigned long long findCount ( unsigned long long N ) { unsigned long long ans = ( expo ( 26 , N ) - expo ( 5 , N ) - expo ( 21 , N ) ) % mod ; ans += mod ; ans %= mod ; return ans ; } int main ( ) { unsigned long long N = 3 ; cout << findCount ( N ) ; return 0 ; }