Search code examples
pythonequation-solving

Solve a simultaneous equation with product of the 2 variables in Python?


If i have 2 equations:

x = ab

and

n = a+b

where x and n are known, and a and b are large whole numbers, how can I solve them using Python?


Solution

  • a and b are the solutions of: X^2 - nX + x = 0

    d = n*n - 4*x
    a = (- b - d**0.5)/2
    b = (- b + d**0.5)/2