+ 1
Prime number test
Let me know a better way to check whether a number is prime or not. https://code.sololearn.com/cgCjY1UDVzWO/?ref=app
2 Réponses
+ 9
You don't need to check all the way up to x. If x isn't divisible by any number up to sqrt(x)+1, it is a prime number.
Also, you don't need to check every single possible divisor. You can check if x is divisible by 2 or 3 and then go from 3 up to sqrt(x) in steps of 2.