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

Function solution

project_euler/problem_136/sol1.py:31–59  ·  view source on GitHub ↗

Define n count list and loop over delta, y to get the counts, then check which n has count == 1. >>> solution(3) 0 >>> solution(10) 3 >>> solution(100) 25 >>> solution(110) 27

(n_limit: int = 50 * 10**6)

Source from the content-addressed store, hash-verified

29
30
31def solution(n_limit: int = 50 * 10**6) -> int:
32 """
33 Define n count list and loop over delta, y to get the counts, then check
34 which n has count == 1.
35
36 >>> solution(3)
37 0
38 >>> solution(10)
39 3
40 >>> solution(100)
41 25
42 >>> solution(110)
43 27
44 """
45 n_sol = [0] * n_limit
46
47 for delta in range(1, (n_limit + 1) // 4 + 1):
48 for y in range(4 * delta - 1, delta, -1):
49 n = y * (4 * delta - y)
50 if n >= n_limit:
51 break
52 n_sol[n] += 1
53
54 ans = 0
55 for i in range(n_limit):
56 if n_sol[i] == 1:
57 ans += 1
58
59 return ans
60
61
62if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected