omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / count-in-factors / oracle.py
| 1 | # Independent reference for "Count in factors" (Python 3, standard library only). |
| 2 | # expected.txt is this program's stdout; omc never produced it. |
| 3 | def factors(n): |
| 4 | out, p = [], 2 |
| 5 | while p * p <= n: |
| 6 | while n % p == 0: |
| 7 | out.append(p) |
| 8 | n //= p |
| 9 | p += 1 if p == 2 else 2 |
| 10 | if n > 1: |
| 11 | out.append(n) |
| 12 | return out |
| 13 | for n in list(range(1, 26)) + list(range(2144, 2157)) + [600851475143, 1000000000000]: |
| 14 | print(f"{n} = " + (" x ".join(map(str, factors(n))) if n > 1 else "1")) |