Stopping at n/2 is the natural next improvement to code that goes all the way to n. From there you can go the next step of stopping at square root of n, and from there you can do even smarter things!...
Type: Posts; User: KevinWorkman
Stopping at n/2 is the natural next improvement to code that goes all the way to n. From there you can go the next step of stopping at square root of n, and from there you can do even smarter things!...
You also only need to check up to n/2, where n is the number you're checking for prime-ness.
When you say it didn't work, what exactly do you mean? What exactly does this program do? Hard code it into an SSCCE with some numbers that result in the broken behavior.
Also, take a step back...