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

Function solution

project_euler/problem_073/sol1.py:22–47  ·  view source on GitHub ↗

Returns number of fractions lie between 1/3 and 1/2 in the sorted set of reduced proper fractions for d ≤ max_d >>> solution(4) 0 >>> solution(5) 1 >>> solution(8) 3

(max_d: int = 12_000)

Source from the content-addressed store, hash-verified

20
21
22def solution(max_d: int = 12_000) -> int:
23 """
24 Returns number of fractions lie between 1/3 and 1/2 in the sorted set
25 of reduced proper fractions for d ≤ max_d
26
27 >>> solution(4)
28 0
29
30 >>> solution(5)
31 1
32
33 >>> solution(8)
34 3
35 """
36
37 fractions_number = 0
38 for d in range(max_d + 1):
39 n_start = d // 3 + 1
40 n_step = 1
41 if d % 2 == 0:
42 n_start += 1 - n_start % 2
43 n_step = 2
44 for n in range(n_start, (d + 1) // 2, n_step):
45 if gcd(n, d) == 1:
46 fractions_number += 1
47 return fractions_number
48
49
50if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected