MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / get_totients

Function get_totients

project_euler/problem_070/sol1.py:37–55  ·  view source on GitHub ↗

Calculates a list of totients from 0 to max_one exclusive, using the definition of Euler's product formula. >>> get_totients(5) [0, 1, 1, 2, 2] >>> get_totients(10) [0, 1, 1, 2, 2, 4, 2, 6, 4, 6]

(max_one: int)

Source from the content-addressed store, hash-verified

35
36
37def get_totients(max_one: int) -> list[int]:
38 """
39 Calculates a list of totients from 0 to max_one exclusive, using the
40 definition of Euler's product formula.
41
42 >>> get_totients(5)
43 [0, 1, 1, 2, 2]
44
45 >>> get_totients(10)
46 [0, 1, 1, 2, 2, 4, 2, 6, 4, 6]
47 """
48 totients = np.arange(max_one)
49
50 for i in range(2, max_one):
51 if totients[i] == i:
52 x = np.arange(i, max_one, i) # array of indexes to select
53 totients[x] -= totients[x] // i
54
55 return totients.tolist()
56
57
58def has_same_digits(num1: int, num2: int) -> bool:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected