Skip to content

Instantly share code, notes, and snippets.

@huseyinyilmaz
Created October 9, 2010 09:41
Show Gist options
  • Save huseyinyilmaz/618064 to your computer and use it in GitHub Desktop.
Save huseyinyilmaz/618064 to your computer and use it in GitHub Desktop.
11 digit prime number generator
# Searches for 11 digits prime numbers
#
# This one is really slow for big numbers
# def isprime(num):
# val = num-1L
# while not val == 1L :
# if num%val == 0L:
# #print str(num) + "%" + str(val) + "==0"
# return False
# val = val -1L
# return True
# prime numbers are only divisible by unity and themselves
# (1 is not considered a prime number by convention)
# source: http://www.daniweb.com/code/snippet216880.html
def isprime(n):
'''check if integer n is a prime'''
# 0 and 1 are not primes
if n < 2L:
return False
# 2 is the only even prime number
if n == 2L:
return True
# all other even numbers are not primes
if not n & 1L:
return False
# range starts with 3 and only needs to go up the squareroot of n
# for all odd numbers
for x in range(3L, long(n**0.5)+1L, 2L):
if n % x == 0:
return False
return True
def find_prime(start,r):
"""Finds prime numbers between start and end value."""
primes = [val+start for val in range(r) if isprime(val+start)]
for p in primes:
print "Prime number = " + str(p)
find_prime(10000000000L,1000L)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment