• + 0 comments

    C++ Solution, may not be the best, but works.

    int primeCount(long n) 
    {
        int result = 0;
        double long x = 1;
        
        for(int i = 2; i < 50; ++i)
        {     
            bool isPrime = true;
            
            for(int j = 2; j <= sqrt(i); ++j)
            {
                if(i % j == 0 && i != 2)
                {
                    isPrime = false;
                    break;
                }
            }
            
            if(isPrime)
            {
                x *= i;
                
                if(x > n) break;
                else if (x == n) 
                {
                    result++; 
                    break;
                }
            
                result++;
            }
        }
        
        return result;
    }