Skip to content

Instantly share code, notes, and snippets.

@razimantv
Created December 10, 2017 21:44
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 razimantv/366121129fd37fc40b7418a70d434d1b to your computer and use it in GitHub Desktop.
Save razimantv/366121129fd37fc40b7418a70d434d1b to your computer and use it in GitHub Desktop.
Prime tree elements
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