Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Exactly, multiples of 2 can't be a prime, so skipping this saves a function call (that itself only does one comparison), so it is a very simple and relatively obvious optimization. But actually every multiple of a number per definition cannot be a prime, you can't just change the step size, but there are some nifty tricks to approach the problem from a different angle.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: