Last active
January 23, 2016 09:37
-
-
Save buzzerrookie/9eeee8f8ca33bcc617a0 to your computer and use it in GitHub Desktop.
Python code for twin prime pairs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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