Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
576 B
1
Indexable
Never
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
Leave a Comment