Skip to content

Commit a343f54

Browse files
Merge pull request #620 from jbhavya11/master
euler totient in python code
2 parents 1d22368 + 2f1ed0d commit a343f54

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

euler-totient-in_python.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# A simple Python3 program
2+
# to calculate Euler's
3+
# Totient Function
4+
5+
# Function to return
6+
# gcd of a and b
7+
def gcd(a, b):
8+
9+
if (a == 0):
10+
return b
11+
return gcd(b % a, a)
12+
13+
# A simple method to evaluate
14+
# Euler Totient Function
15+
def phi(n):
16+
17+
result = 1
18+
for i in range(2, n):
19+
if (gcd(i, n) == 1):
20+
result+=1
21+
return result
22+
23+
# Driver Code
24+
for n in range(1, 11):
25+
print("phi(",n,") = ",
26+
phi(n), sep = "")
27+
28+
# This code is contributed
29+
# by Smitha

0 commit comments

Comments
 (0)