If two prime difference is 2 then number is called twin prime number. So to check number is twin prime or not
First check number is prime or not.
Second check both prime number difference is 2 or not if difference is 2 then number is twin prime number.
Program
def pr(x):
for i in range(2,x):
if(x%i==0):
print("number is not prime")
return False
return True
n1=int(input("enter number1"))
n2= int(input("enter number2"))
if pr(n1) and pr(n2):
if abs(n1-n2)==2:
print("number is twin prime")
else:
print("number is not twin prime")
Example
enter number1 5
enter number2 3
Both 5 and 3 are prime number
Difference between 5 and 3 is 2 so number is twin prime number.
Note
How to check 5 is prime or not
Smaller than 5 number is
2,3,4
5 cannot divided 2,3,4 so number 5 is prime number.
0 Comments