# 06. Techfest and the Queue

The problem can be found at the following link: [Question Link](https://www.geeksforgeeks.org/problems/techfest-and-the-queue1044/1)

![](https://badgen.net/badge/Level/Medium/yellow)

## My Approach

The `primePowers` function is implemented to count the prime factors of a given number. The `sumOfPowers` function iterates from `a` to `b` and sum the total prime factors using the `primePowers` function.

## Time and Auxiliary Space Complexity

* **Time Complexity:** `O(b * sqrt(max_element))`, where max\_element is the maximum number in the range \[a, b].
* **Auxiliary Space Complexity:** `O(1)`

## Code (C++)

```cpp
class Solution {
public:
    int primePowers(int n)
    {
        int cnt = 0;
        for(int i = 2; i <= sqrt(n); i++)
        {
            while(n % i == 0)
            {
                cnt++;
                n = n / i;
            }
        }
        
        if(n > 1)
            cnt++;
        
        return cnt;
    }
    
    int sumOfPowers(int a, int b)
    {
        int cnt = 0;
        for(int i = a; i <= b; i++)
            cnt += primePowers(i);
        
        return cnt;
    }
};
```

## Contribution and Support

For discussions, questions, or doubts related to this solution, please visit our [discussion section](https://github.com/getlost01/gfg-potd/discussions). We welcome your input and aim to foster a collaborative learning environment.

If you find this solution helpful, consider supporting us by giving a `⭐ star` to the [getlost01/gfg-potd](https://github.com/getlost01/gfg-potd) repository.

```
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gl01.gitbook.io/gfg-editorials/2024/01-2024-jan-5/06-techfest-and-the-queue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
