noether/prbraid/math.py
2025-06-11 11:11:35 +10:00

24 lines
529 B
Python

# Euler's Totient (Phi) Function
def totient(n):
phi = int(n > 1 and n)
for p in range(2, int(n ** .5) + 1):
if not n % p:
phi -= phi // p
while not n % p:
n //= p
#if n is > 1 it means it is prime
if n > 1: phi -= phi // n
return phi
def orbit(b, m):
generated = []
x = b
for i in range(m):
x = (x * b) % m
if x not in generated:
generated.append(x)
return generated
def order(b, m):
return len(orbit(b, m))