andrewrk / zig-async-demo

Comparing concurrent code example programs between other languages and Zig
55 stars 9 forks source link

Look for factors only up to sqrt + 1 #6

Open hectormonacci opened 3 years ago

hectormonacci commented 3 years ago

No need to keep searching for factors among lower prime numbers once you reach the square root (plus 1) of the number you are testing for primality. If you get there, you can safely quit the search: your number under testing for primality is a prime number. This, by the way, speeds up the program tremendously.