-6

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?

Ananay Gupta
  • 355
  • 3
  • 14

2 Answers2

0

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
marc
  • 914
  • 6
  • 18
0

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
mickNeill
  • 346
  • 5
  • 22
  • Thanks, mickNeill. This does work, but for small numbers. Instead of the math.sqrt , i used (...)**0.5, which did the trick – Ananay Gupta Apr 24 '18 at 15:03