Skip to content

Commit

Permalink
Euler's Totient Function
Browse files Browse the repository at this point in the history
  • Loading branch information
detel committed Jul 10, 2015
1 parent 7a5022b commit 13c55a6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Phi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from math import sqrt

def phi(num):
result = num

for i in xrange(2,int(sqrt(num))+1):
if num%i == 0:
while num%i == 0:
num /= i
result -= result/i

if num>1:
result -= result/num

return result

for x in xrange(1,10):
print phi(x)

0 comments on commit 13c55a6

Please sign in to comment.