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

Function solution

project_euler/problem_135/sol1.py:23–51  ·  view source on GitHub ↗

returns the values of n less than or equal to the limit have exactly ten distinct solutions. >>> solution(100) 0 >>> solution(10000) 45 >>> solution(50050) 292

(limit: int = 1000000)

Source from the content-addressed store, hash-verified

21
22
23def solution(limit: int = 1000000) -> int:
24 """
25 returns the values of n less than or equal to the limit
26 have exactly ten distinct solutions.
27 >>> solution(100)
28 0
29 >>> solution(10000)
30 45
31 >>> solution(50050)
32 292
33 """
34 limit = limit + 1
35 frequency = [0] * limit
36 for first_term in range(1, limit):
37 for n in range(first_term, limit, first_term):
38 common_difference = first_term + n / first_term
39 if common_difference % 4: # d must be divisible by 4
40 continue
41 else:
42 common_difference /= 4
43 if (
44 first_term > common_difference
45 and first_term < 4 * common_difference
46 ): # since x, y, z are positive integers
47 frequency[n] += 1 # so z > 0, a > d and 4d < a
48
49 count = sum(1 for x in frequency[1:limit] if x == 10)
50
51 return count
52
53
54if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected