Q. Check whether a given number is prime or not with the best approach.
Implement is_prime(n) to return True if n is prime and False otherwise. Optimize the check by testing divisors only through the square root of n.
Input: A non-negative integer n.
Output: A Boolean indicating whether n is prime.
def is_prime(n):