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?
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?
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
Try this
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