Prime

Note

We check if number is a Square root by dividing with only numbers from 2 to square root of number.

That is because factors occur in pairs, one greater than equal to or lesser than equal to the square root.

Hence there is atleast one factor lesser than square root of the number. Thus we check it only till then.

Java

Python