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/totient-function/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 / totient-function / oracle.py` 14 lines ยท 571 bytes Raw Blame History 1 # Independent reference for "Totient function" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 import math 4 for n in range(1, 26): 5 phi = sum(1 for k in range(1, n + 1) if math.gcd(n, k) == 1) 6 print(f"phi({n}) = {phi}" + (", prime" if phi == n - 1 else "")) 7 N = 100000 8 s = bytearray([1]) * (N + 1) 9 s[0] = s[1] = 0 10 for i in range(2, math.isqrt(N) + 1): 11 if s[i]: 12 s[i * i::i] = bytes(len(range(i * i, N + 1, i))) 13 for lim in [100, 1000, 10000, 100000]: 14 print(f"primes up to {lim}: {sum(s[:lim + 1])}")