Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5410c95

Browse filesBrowse files
aniakubikabranhe
authored andcommitted
added euler totien function
1 parent 493ffc8 commit 5410c95
Copy full SHA for 5410c95

File tree

Expand file treeCollapse file tree

1 file changed

+24
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-0
lines changed

‎math/eulerTotient.py

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from math import sqrt
2+
3+
"""
4+
this function calculate euler totien function
5+
"""
6+
def eulerTotienFunction(n):
7+
if n == 1:
8+
return 1
9+
result = 1
10+
temp = n
11+
for i in range(2,int(sqrt(n))+10):
12+
if (temp % i == 0):
13+
j = 0
14+
while(temp % i == 0):
15+
j += 1
16+
temp //= i
17+
result = result * (i**(j-1)) * (i-1)
18+
if temp == n:
19+
return n-1
20+
return result
21+
22+
23+
24+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.