09. Largest Prime Factor
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
To find the largest prime factor of a given number n
,
I iterate from 2
up to the square root of n
.
During this iteration, I repeatedly divide n
by i
as long as n
is divisible by i
, and keep track of the largest factor encountered.
Finally, I return the largest factor, which is also the largest prime factor of n
.
Time Complexity: The loop runs from 2
to the square root of n
, which results in a time complexity of O(sqrt(n))
.
Auxiliary Space Complexity: O(1)
as I am using a constant amount of extra space to store the result.
For discussions, questions, or doubts related to this solution, please visit our . 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 repository.