diff options
Diffstat (limited to 'challenge-155/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-155/paulo-custodio/python/ch-1.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-155/paulo-custodio/python/ch-1.py b/challenge-155/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..e1cdaebf76 --- /dev/null +++ b/challenge-155/paulo-custodio/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +# Challenge 155 +# +# TASK #1 > Fortunate Numbers +# Submitted by: Mohammad S Anwar +# Write a script to produce first 8 Fortunate Numbers (unique and sorted). +# +# According to Wikipedia +# +# A Fortunate number, named after Reo Fortune, is the smallest integer m > 1 +# such that, for a given positive integer n, pn# + m is a prime number, where +# the primorial pn# is the product of the first n prime numbers. +# +# Expected Output +# 3, 5, 7, 13, 17, 19, 23, 37 + +from math import prod +from sympy import isprime, nextprime + +fortunate = {} + +primes = [2] +while len(fortunate) < 8: + p = prod(primes) + m = 2 + while not isprime(p + m): + m += 1 + fortunate[m] = 1 + primes.append(nextprime(primes[-1])) + +print(", ".join(map(str, sorted(fortunate.keys())))) |
