Prime Number Long way

So let's say I have couple numbers
10
13
22
99
10000
345
5834
5567
how i test if they are prime or not using the long way (like square root)?
For large numbers that would require too much memory for all the numbers create a prime sieve up to the sqrt of the largest and check if a number is divisible by any of them if not it is prime. For smaller numbers you can simply create a sieve from 1->largest and check if they are prime.

Creating the sieves are very easy.
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Ps if you create a sieve use a std::vector<bool> or std::bitset<BITS> I would suggest std::vector<bool> though.
http://www.cplusplus.com/reference/vector/vector-bool/
Topic archived. No new replies allowed.