In Project Euler problem 3, where we have to find the largest prime factor of a number, one of the solution i came across is
long long int find(long long int n){
long k = 2;
while (k * k <= n)
{
if (n % k == 0)
{
n /= k;
}
else
{
++k;
}
}
return n;
}
The solution is perfect but i fail to understand the while condition here( while k*k<=n). Isnt the condition should be isPrime(n)? How does checking k*k<=n gives the right answer here?