I'm writing a computer program that finds prime numbers. It currently loops through a number (n) and starts at 2 (k). It checks if n is divisible by k. If so, it declares the number as not prime and moves on. If not, 1 is added to k and the division is repeated. This goes on until k is equal to half of n.
Is there a more efficent way to do it?
yes the sieve of Eratosthenes, the sieve of atkin, and the sieve of sundaram would all fit the bill. as would Euler's sieve etc.