interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

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.
3import math
4for 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 ""))
7N = 100000
8s = bytearray([1]) * (N + 1)
9s[0] = s[1] = 0
10for 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)))
13for lim in [100, 1000, 10000, 100000]:
14 print(f"primes up to {lim}: {sum(s[:lim + 1])}")