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

Function solution

project_euler/problem_070/sol1.py:75–97  ·  view source on GitHub ↗

Finds the value of n from 1 to max such that n/φ(n) produces a minimum. >>> solution(100) 21 >>> solution(10000) 4435

(max_n: int = 10000000)

Source from the content-addressed store, hash-verified

73
74
75def solution(max_n: int = 10000000) -> int:
76 """
77 Finds the value of n from 1 to max such that n/φ(n) produces a minimum.
78
79 >>> solution(100)
80 21
81
82 >>> solution(10000)
83 4435
84 """
85
86 min_numerator = 1 # i
87 min_denominator = 0 # φ(i)
88 totients = get_totients(max_n + 1)
89
90 for i in range(2, max_n + 1):
91 t = totients[i]
92
93 if i * min_denominator < min_numerator * t and has_same_digits(i, t):
94 min_numerator = i
95 min_denominator = t
96
97 return min_numerator
98
99
100if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 2

get_totientsFunction · 0.85
has_same_digitsFunction · 0.85

Tested by

no test coverage detected