用 Python 中的 2 个变量的乘积求解联立方程?

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

如果我有 2 个方程式:

x = ab

n = a+b

其中 x 和 n 已知,a 和 b 是大整数,我如何使用 Python 解决它们?

a 和 b 是以下的解:X^2 - nX + x = 0

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

试试这个

import math
n = int(raw_input('What is the value of n?'))
x = int(raw_input('What is the value of x?'))
aEqu1 = (n + math.sqrt((n**2) - (4*x)))/2
bEqu2 = (n - math.sqrt((n**2) - (4*x)))/2

print "a equals ", aEqu1
print "b equals ", bEqu2