diff options
Diffstat (limited to 'challenge-158/paulo-custodio/python/ch-2.py')
| -rw-r--r-- | challenge-158/paulo-custodio/python/ch-2.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-158/paulo-custodio/python/ch-2.py b/challenge-158/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..1f7220d82b --- /dev/null +++ b/challenge-158/paulo-custodio/python/ch-2.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +# Challenge 158 +# +# TASK #2 > First Series Cuban Primes +# Submitted by: Mohammad S Anwar +# Write a script to compute first series Cuban Primes <= 1000. Please refer +# wikipedia page for more informations. +# +# Output +# 7, 19, 37, 61, 127, 271, 331, 397, 547, 631, 919. +# +# p=(x^3-y^3)/(x-y), x=y+1, y>0 +# <=> p=3y^2+3y+1, y>0 + +from sympy import isprime + +def cuban_primes(limit): + out = [] + y = 1 + p = 0 + while True: + p = 3 * y * y + 3 * y + 1 + if isprime(p): + out.append(p) + if p >= limit: + break + y += 1 + return out + +print(", ".join(map(str, cuban_primes(1000)))) |
