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

Function solution

project_euler/problem_072/sol1.py:27–46  ·  view source on GitHub ↗

Returns an integer, the solution to the problem >>> solution(10) 31 >>> solution(100) 3043 >>> solution(1_000) 304191

(limit: int = 1_000_000)

Source from the content-addressed store, hash-verified

25
26
27def solution(limit: int = 1_000_000) -> int:
28 """
29 Returns an integer, the solution to the problem
30 >>> solution(10)
31 31
32 >>> solution(100)
33 3043
34 >>> solution(1_000)
35 304191
36 """
37
38 # generating an array from -1 to limit
39 phi = np.arange(-1, limit)
40
41 for i in range(2, limit + 1):
42 if phi[i] == i - 1:
43 ind = np.arange(2 * i, limit + 1, i) # indexes for selection
44 phi[ind] -= phi[ind] // i
45
46 return int(np.sum(phi[2 : limit + 1]))
47
48
49if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected