Count of N size strings consisting of at least one vowel and one consonant | Java 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 code
class GFG { static int mod = ( int ) ( 1e9 + 7 ) ; static int expo ( int base , int exponent ) { int 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 ; } static int findCount ( int N ) { int ans = ( expo ( 26 , N ) - expo ( 5 , N ) - expo ( 21 , N ) ) % mod ; ans += mod ; ans %= mod ; return ans ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . print ( findCount ( N ) ) ; } }