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.