Damon is a mathematician, and he calls a integer N Damon Prime if N+1 and N-1 both are prime numbers. He will give you an integer N, you need to find whether the number is Damon Prime or not.  
For example:  4 is a damon prime, 5 is not a damon prime, 102 is a damon prime, 9 is not a damon prime, etc . 
Example 1:
Input: N = 4
Output: "Yes" 
Explanation: According to Damon 4
is a Damon Prime.
Example 2:
Input: N = 5
Output: "No"
Explanation: According to Damon 5
is not a Damon Prime. 
Your Task:  
You dont need to read input or print anything. Complete the function damonPrime() which takes N as input parameter and returns "Yes" if N is a Damon Prime else return "No".
Expected Time Complexity: O(sqrt(N))
Expected Auxiliary Space: O(1)
Constraints:
1<= N <=10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Starter code: #User function Template for python3



#User function Template for python3

class Solution:

    def damonPrime (self, N):

        # code here 

Solutions:
from math import sqrt

def fun(n):
	for i in range(2, int(sqrt(n) + 1)):
		if n % i == 0:
			return 0
	return 1

class Solution:

	def damonPrime(self, N):
		if fun(N - 1) == 1 and fun(N + 1) == 1:
			return 'Yes'
		else:
			return 'No'


import math

def isprime(n):
	if n <= 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return 0
	return 1

class Solution:

	def damonPrime(self, n):
		if isprime(n + 1) and isprime(n - 1):
			return 'Yes'
		return 'No'


class Solution:

	def damonPrime(self, N):

		def is_prime(n):
			i = 2
			while i * i <= n:
				if n % i == 0:
					return False
				i += 1
			return True
		if is_prime(N):
			return 'No'
		if is_prime(N - 1) and is_prime(N + 1):
			return 'Yes'
		return 'No'


class Solution:

	def damonPrime(self, N):

		def isPrime(num):
			if num < 2:
				return 0
			for i in range(2, int(num ** 0.5) + 1):
				if num % i == 0:
					return 0
			return 1
		if isPrime(N - 1) == 1 and isPrime(N + 1) == 1:
			return 'Yes'
		return 'No'


import math

class Solution:

	def isPrime(self, num):
		if num <= 1:
			return False
		i = 2
		while i <= int(math.sqrt(num)):
			if num % i == 0:
				return False
			i += 1
		return True

	def damonPrime(self, N):
		if self.isPrime(N + 1) and self.isPrime(N - 1):
			return 'Yes'
		else:
			return 'No'