Find the count of M character words which have at least one character repeated | C ++ implementation for the above approach ; Function to return the factorial of a number ; Function to return the value of nPr ; Function to return the total number of M length words which have at least a single character repeated more than once ; Driver code
#include <math.h> NEW_LINE #include <iostream> NEW_LINE using namespace std ; int fact ( int n ) { if ( n <= 1 ) return 1 ; return n * fact ( n - 1 ) ; } int nPr ( int n , int r ) { return fact ( n ) / fact ( n - r ) ; } int countWords ( int N , int M ) { return pow ( N , M ) - nPr ( N , M ) ; } int main ( ) { int N = 10 , M = 5 ; cout << ( countWords ( N , M ) ) ; return 0 ; }