diff options
Diffstat (limited to 'challenge-041/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-041/paulo-custodio/python/ch-1.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-041/paulo-custodio/python/ch-1.py b/challenge-041/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..8eb700c727 --- /dev/null +++ b/challenge-041/paulo-custodio/python/ch-1.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +# Challenge 041 +# +# TASK #1 +# Write a script to display attractive number between 1 and 50. +# A number is an attractive number if the number of its prime factors is also +# prime number. +# +# The number 20 is an attractive number, whose prime factors are 2, 2 and 5. +# The total prime factors is 3 which is also a prime number. + +from primePy import primes + +def is_attractive(n): + factors = primes.factors(n) + num_factors = len(factors) + return num_factors != 1 and primes.check(num_factors) + +out = [] +for n in range(1, 50+1): + if is_attractive(n): + out.append(n) +print(", ".join([str(x) for x in out])) |
