Skip to content

Instantly share code, notes, and snippets.

@harshvb7
Created November 20, 2015 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshvb7/7536200d554cf95efb6a to your computer and use it in GitHub Desktop.
Save harshvb7/7536200d554cf95efb6a to your computer and use it in GitHub Desktop.
import math
l = input('Enter lowest no.')
h = input('Enter higest no.')
def check_prime(n):
if n < 2:
return False
for i in range(2, int(math.sqrt(n)) + 1): # see if num is divisible by any number up to the square root of num
if n % i == 0:
return False
return True
for i in range(l, h-1):
if check_prime(i) and check_prime(i+2):
print 'Smallest twins in given range: (%d %d)' %(i, i+2)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment