Write a most optimized code to find if a number is prime or not.
Implement is_prime(n) to return a Boolean. The input is one integer, and the function must return True only for prime numbers. Use an algorithm that avoids testing every integer up to n; for example, is_prime(29) returns True, while is_prime(1) returns False.
def is_prime(n):