blob: 8eb700c7278534f2e26a4d4ddd098797a57adc3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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]))
|