Count prime factors of N!

Count prime factors of N!
Given an integer N, the task is to count the number of prime factors of N!.

Input: N = 5Output: 3Explanation: Factorial of 5 = 120. Prime factors of 120 are {2, 3, 5}. Therefore, the count is 3.
Input: N = 1Output: 0

Naive Approach: Follow the steps to solve the problem :Initialize a variable, say fac, to store the factorial of a number.
Initialize a variable, say count, to count the prime factors of N!.
Iterate over the range [2, fac] and if the number is not prime, increment count.
Print the count as the answer.
Below is the implementation of the above approach:


using namespace std;

int factorial(int f)
    if (f == 0 || f == 1) {
        return 1;
    else {
        return (f * factorial(f – 1));

bool isPrime(int element)
    for (int i = 2;