Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/factors-of-an-integer/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / factors-of-an-integer / oracle.py` 18 lines ยท 692 bytes Raw Blame History 1 # Independent reference for "Factors of an integer" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 def prime_powers(n): 4 f, p = {}, 2 5 while p * p <= n: 6 while n % p == 0: 7 f[p] = f.get(p, 0) + 1 8 n //= p 9 p += 1 10 if n > 1: 11 f[n] = f.get(n, 0) + 1 12 return f 13 # every divisor is a product of prime powers p^e with 0 <= e <= the exponent of p in n 14 for n in [1, 45, 53, 64, 720, `1000000`, `600851475143`]: 15 divs = [1] 16 for p, e in prime_powers(n).items(): 17 divs = [d * p ** k for d in divs for k in range(e + 1)] 18 print(f"factors of {n}: " + " ".join(map(str, sorted(divs))))