Created
December 10, 2017 21:44
-
-
Save razimantv/366121129fd37fc40b7418a70d434d1b to your computer and use it in GitHub Desktop.
Prime tree elements
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
primes = [2, 3, 5, 7] | |
parent = [-1, -1, -1, -1] | |
digits = [1, 3, 7, 9] | |
def isprime(N): | |
i = 2 | |
while i * i <= N: | |
if N % i == 0: | |
return False | |
i += 1 | |
return True | |
i = 0 | |
while i < len(primes): | |
p = primes[i] | |
for d in digits: | |
if isprime(p * 10 + d): | |
primes.append(p * 10 + d) | |
parent.append(i) | |
i += 1 | |
print(len(primes)) | |
print(primes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment