Skip to content

Instantly share code, notes, and snippets.

@buzzerrookie
Last active January 23, 2016 09:37
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 buzzerrookie/9eeee8f8ca33bcc617a0 to your computer and use it in GitHub Desktop.
Save buzzerrookie/9eeee8f8ca33bcc617a0 to your computer and use it in GitHub Desktop.
Python code for twin prime pairs
#!/usr/bin/python
M = 1000
N = 1500
isprime = [True] * (N + 1)
isprime[0] = False
isprime[1] = False
count = 0;
i = 2
while i <= N:
if not isprime[i]:
i += 1
continue
isprime[i] = True
if (i-2) >= M and isprime[i - 2]:
count += 1
j = 2
while (j * i) <= N:
isprime[j * i] = False
j += 1
i += 1
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment