Does this algorithm find prime numbers only? I'm writing code to help find prime numbers within a certain range. Here's my general pseudo-code:


*

*Iterate through every single number in the range.

*If the number is 2, 3, 5, or 7; then mark it as a prime number.

*If the number is NOT divisible by 2, 3, 5, or 7; then it's also a prime number.


Think about it. Checking divisibility by 2 already removed even numbers. Three, five, and 7 are other fundamental prime numbers, so any other non-prime number has to be a divisor of any of these. I tested this algorithm with all numbers between 1-100, and it worked. But would it work for all numbers?
 A: For any integer $n \ge 2$ either $n$ is prime or $n$ has a prime factor less than or equal to $\sqrt{n}$. So, if you are only finding prime numbers within a range of $1$ through $N$, then you need to check divisibility by every prime less than or equal to $\sqrt{N}$. 
Since you were only focused on the range $1$ through $100$, you need to check for divisibility by all primes up to $\sqrt{100} = 10$. So testing $2$, $3$, $5$, and $7$ is sufficient. However, if you go up to $121 = 11^2$ or higher, testing only $2$, $3$, $5$, and $7$ will not work. 
A: Hint:
1. Prime numbers greater than 5 are either can be formed as $6k-1$ or $6k+1$.
2. If x can not be divided by 2, 3, 5, 7,..., and k (k is the greatest prime number less than square root of x.) then x is prime.
Add your code.
A: Your ideas are interesting for the problem of "finding all prime numbers within a range". The fact that you verified that your idea works for all numbers below $100$ (except for $1$, which isn't considered prime, but let's put that aside) proves that your algorithm is correct for the range $[2,100]$. Not optimal by any means, but it is.
Your algorithm relies on a simple observation : a number ($\geq2$) is prime if and only if it can be divided by another number than $1$ and itself. You noticed that it works for numbers below $100$, and others have already pointed out that it fails for $121 = 11\times 11$. With this observation, you might deduce that you need to check also the divisibility by prime numbers higher than $7$ like $11$, $13$...
But where should we stop ? There is an infinity of prime numbers and you can't possibly check divisibility by all of them ! This issue is solved by noticing that a number $n$ can't have all its prime divisors higher than $\sqrt n$. Hence, to verify the primality of $149$, you need to check for divisibility by all the primes below $\sqrt{149}$, that is to say $2,3,5,7,11$.
This yields another issue : how could we find what are the prime numbers below $\sqrt{n}$ ? Well, since we did your check for every number below $n$ (because you want all the primes in the range), we can reuse the previous results : simply iterate through all your results up to $\sqrt n$ to have all these "fundamental primes for $n$" as you said.
However, as you may begin to understand now, this is not efficient : the further we go, the more numbers we have to check for divisibility with. Even if we managed to have a pretty good algorithm if we would like primality of one given $n$, maybe we could do better for a whole range. 
If you know that a number $n$ is divisisible by a prime $p$, what can you say of $n+p$ ? It is divisible by $p$ too ! And to know this, you didn't even had to calculate a division or a modulo !
This is the basis of the Erathostenes' sieve, which is way more efficient than yours. You should click on the links for all the details and implementation : the gif at the top of the page is worth a thousand words.
TL;DR : No, it doesn't work for all numbers, because you stopped at $7$. If you define your range as $[2,n]$, you need to include all the prime numbers below $\sqrt{n}$. This is why it works for $100$ but not $121$.
A: No, I believe you are incorrectly implementing Eratosthenes Sieve, in which you mark the multiples of prime numbers as non prime, starting with $2$.
Your algorithm fails for $121 = 11 \times 11$, as user7530 kindly pointed out.
A: For an algorithm to find primes within a certain range, yes, taking the primes under the square root of the maximum value will suffice. However, what if this was any maximum value?, and what happens when your square root (of 1000 for example) isn't an integer?, i'd say that you need to find the primes below the square root first, then run the function.
