Sum of two integer is given. What will be the product?

83 Views Asked by At

I came across the following question:

If the sum of two integers is 30, then their product maybe?
1. -5400
2. -1000
3. 200
4. 224.75
5. 250

So I solved it by the following method:

let two numbers be x and y  
Hence "x + y = 30"   
and x*y = assumed a  
Quadratic equation will be "x*(30-x) = a". Further simplyfying to:
x^2 -30x + a = 0

So two roots will be:    
(x, y) = (-(-30) ± sqrt(30^2 - 4*a)) / 2

I substituted values from options. Ultimately I found that options 1, 2 & 3 are correct. But I did this by trial and error (kind of).

Is there any way to find without substituting options?

P.S. I want to implement this in python. But I am struggling to solve it by hand.

2

There are 2 best solutions below

2
On

Well, all you had to do was check the determinant of the quadratic equation. $$b^2\ge4ac$$ $$30^2\ge 4a$$ $$a\le 225$$ Hence for all products below $225$, there will be two numbers which satisfy the required conditions. This tells us that options $1,2,3,4$ are correct. However, two integers when multiplied do not give option $4$. Therefore, the answer is options $1,2$ and $3$.

0
On

Does this help?:

Let $x=15+k$ and $y=15-k$ where $k$ is an integer. Then $x+y=30$ and

$xy=(15+k)(15-k) = 15^2 - k^2 = 225 - k^2$. So you need to check integers in that form.

In fact, $225 - k^2$, $k=0,1,2, \dots$ gives you the complete list of such numbers. That is

$225, 224, 221, 216, 200, \dots 56, 29,0,-31, -64, -136, -175, -216,-259 \dots$ So, if a number is in the list then it is a product; if not, it is not a product.

You can also use $xy = 225 - k^2$ to determine for a given number $P$ is a product or not. If $P$ is a product then $P=225 - k^2$. This gives you two important conditions:

i) $P$ is an integer and $P \leq 225$.

ii) $225 - P$ is a perfect square.

If one these conditions is not satisfied then $P$ can not be a product. These conditions are so characteristic that they are sufficient to say for given number is a product. That is, let say $Q$ satisfies i) and ii) then $Q$ is a product for numbers whose sum is $30$. To see, $225-Q = n^2$ for some integer $n$. So, $Q=225 - n^2 = (15 - n)(15 + n)$ and $(15 - n)+(15 - n)=30$.

Consequently, If you can check i) and (logic and) ii) for a given number $P$, you can determine whether it is a product or not.