How the test works
To check whether n is prime you only need to test divisors up to √n. If no integer from 2 up to the square root of n divides it evenly, n is prime. The square-root shortcut works because any factor larger than √n must pair with one smaller than √n, so a smaller divisor would already have been found.