omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / attractive-numbers / oracle.py
| 1 | # Independent reference for "Attractive numbers" (Python 3, standard library only). |
| 2 | # expected.txt is this program's stdout; omc never produced it. |
| 3 | def omega(n): |
| 4 | k, p = 0, 2 |
| 5 | while n > 1: |
| 6 | while n % p == 0: |
| 7 | n //= p |
| 8 | k += 1 |
| 9 | p += 1 |
| 10 | return k |
| 11 | att = [n for n in range(1, 121) if omega(n) in (2, 3, 5, 7)] |
| 12 | print("attractive numbers up to 120 (the count of prime factors, with multiplicity, is prime):") |
| 13 | for i in range(0, len(att), 20): |
| 14 | print("".join(f"{n:4d}" for n in att[i:i + 20])) |