For large numbers, you would have to look deeper and study things like the Sieves of Eratosthenes, Euler etc ... (Sieve of Eratosthenes - Wikipedia, the free encyclopedia)