Computing Eulers Totient Function
I am trying to find an efficient way to compute Euler's totient function
http://en.wikipedia.org/wiki/Euler's_totient_function
What is wrong with this code, it doesn't seem to be working...
def isPrime(a):
return not ( a < 2 or any(a % i == 0 for i in range(2, int(a ** 0.5) +
1)))
def phi(n):
y = 1
for i in range(2,n+1):
if isPrime(i) is True and n % i == 0 is True:
y = y * (1 - 1/i)
else:
continue
return int(y)
No comments:
Post a Comment