Untitled
unknown
plain_text
2 years ago
576 B
18
Indexable
def get_all_solutions_fixing_b(b):
if b == 0:
return 'All N'
solutions = {0}
for k in range(b//2+1, 2*b+1):
r = (2*b-k)*k/(2*k-b)
r = int(r) if int(r) == r else None
if r is not None: solutions.add(r)
return [(a, b) for a in sorted(solutions)]
print(get_all_solutions_fixing_b(5))
# [(0, 5), (5, 5), (8, 5), (21, 5)]
print(get_all_solutions_fixing_b(8))
# [(0, 8), (3, 8), (5, 8), (8, 8), (15, 8)]
print(get_all_solutions_fixing_b(11))
# [(0, 11), (11, 11), (35, 11), (96, 11)]
print(get_all_solutions_fixing_b(0))
# All N
Editor is loading...
Leave a Comment