Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

On top of the answer by Emily L. Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.

while(number!=1 && div <= sqrt(number))

Where sqrt(number) is the square root of the number in each iteration.

If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors and output \$n\$.

On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.

while(number!=1 && div <= sqrt(number))

Where sqrt(number) is the square root of the number in each iteration.

If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors and output \$n\$.

On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.

while(number!=1 && div <= sqrt(number))

Where sqrt(number) is the square root of the number in each iteration.

If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors and output \$n\$.

added 1 character in body
Source Link
Emily L.
  • 16.7k
  • 1
  • 39
  • 89

On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.

while(number!=1 && div <= sqrt(number))

Where sqrt(number) is the square root of the number in each iteration.

If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors anand output \$n\$.

On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.

while(number!=1 && div <= sqrt(number))

Where sqrt(number) is the square root of the number in each iteration.

If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors an output \$n\$.

On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.

while(number!=1 && div <= sqrt(number))

Where sqrt(number) is the square root of the number in each iteration.

If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors and output \$n\$.

Source Link
pepelu
  • 111
  • 4

On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.

while(number!=1 && div <= sqrt(number))

Where sqrt(number) is the square root of the number in each iteration.

If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors an output \$n\$.

lang-c

AltStyle によって変換されたページ (->オリジナル) /