Maximum number of prime factors a number can have with exactly x factors | C ++ implementation to find the maximum count of the prime factors by the count of factors of number ; Function to count number of prime factors of x ; Count variable is incremented for every prime factor of x ; Loop to count the number of the prime factors of the given number ; Driver Code
#include <iostream> NEW_LINE #include <math.h> NEW_LINE using namespace std ; int countPrimeFactors ( int n ) { if ( n == 1 ) return 0 ; int cnt = 0 ; while ( n % 2 == 0 ) { cnt ++ ; n = n / 2 ; } for ( int i = 3 ; i <= sqrt ( n ) ; i += 2 ) { while ( n % i == 0 ) { cnt ++ ; n = n / i ; } } if ( n > 2 ) cnt ++ ; return cnt ; } int main ( ) { int x = 8 ; int prime_factor_cnt = countPrimeFactors ( x ) ; cout << prime_factor_cnt << endl ; return 0 ; }