Leonardo's Prime Factors

Leonardo loves primes and created q queries where each query takes the form of an integer,n. For each n, count the maximum number of distinct prime factors of any number in the inclusive range.

Note: Recall that a prime number is only divisible by 1 and itself, and 1 is not a prime number.

Example

The maximum number of distinct prime factors for values less than or equal to is. One value with distinct prime factors is 30. Another is 42.

Example:

Input:  q = 6, arr = {1, 2, 3, 500, 5000, 10000000000}

Output:

0 1 1 4 5 10

Approach:

C++

#include <bits/stdc++.h>
using namespace std;

int primeCount(long long int N)
{
    vector<longprimes = {23571113,
                           171923293137,
                           41434753};
    int count = 0;
    long  long int pf = primes[0];
    for (int j = 1j < primes.size() && pf <= N && N != 1j++)
    {
        pf = pf * primes[j];
        count++;
    }
    return count;
}

int main()
{
    int q = 6;

    vector<long long int > arr = {123,
                             5005000,
                             10000000000};

    for (int i = 0i < qi++)
    {

        cout << primeCount(arr[i]<< "\n";
    }

    return 0;
}


No comments:

Post a Comment