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

Function solution

project_euler/problem_027/sol1.py:62–87  ·  view source on GitHub ↗

>>> solution(1000, 1000) -59231 >>> solution(200, 1000) -59231 >>> solution(200, 200) -4925 >>> solution(-1000, 1000) 0 >>> solution(-1000, -1000) 0

(a_limit: int = 1000, b_limit: int = 1000)

Source from the content-addressed store, hash-verified

60
61
62def solution(a_limit: int = 1000, b_limit: int = 1000) -> int:
63 """
64 >>> solution(1000, 1000)
65 -59231
66 >>> solution(200, 1000)
67 -59231
68 >>> solution(200, 200)
69 -4925
70 >>> solution(-1000, 1000)
71 0
72 >>> solution(-1000, -1000)
73 0
74 """
75 longest = [0, 0, 0] # length, a, b
76 for a in range((a_limit * -1) + 1, a_limit):
77 for b in range(2, b_limit):
78 if is_prime(b):
79 count = 0
80 n = 0
81 while is_prime((n**2) + (a * n) + b):
82 count += 1
83 n += 1
84 if count > longest[0]:
85 longest = [count, a, b]
86 ans = longest[1] * longest[2]
87 return ans
88
89
90if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

is_primeFunction · 0.70

Tested by

no test coverage detected