# Why is ab+bc+ac = 0 in some situation?

This is originally a Computer Science question, but I ran a equation that is too hard to solve. Here goes.

So the problem is quite simple, given positive integers $a$, $b$, $c$, and calculate $\sqrt{a^2+b^2+c^2}$

But here's the problem, if I calculate any of the squares, I will trigger an integer overflow, where the computer have not enough allocated space to save the result.

So the problem gives me an additional condition: the difference between the minimum of the three and the bigger other two is perfect squares.

That said, if $c$ is the smallest of the three. $b-c$ and $a-c$ will both be perfect squares. And the answer itself is an integer, which means $a^2+b^2+c^2$ is also a perfect square.

So, here's what I got so far.

assume $c$ is the smallest of the three.

let $m=\sqrt{a-c}$, and $n=\sqrt{b-c}$, so $2m^2n^2=2ab-2ac-2bc+2c^2$

and $a^2+b^2+c^2=(a+b-c)^2-2ab+2ac+2bc$

Organize the two, and I am able to get:

$(a+b-c)^2-2(a-c)(b-c)=a^2+b^2+c^2$

And the answer to this problem simply output: $a+b-c$, so $2(a-c)(b-c)$ must be zero under the given condition.

Here's some sample to test it out.

2, 2, 1   - 3
3, 6, 2   - 7
4, 12, 3  - 13


And the following is wrong, since $\sqrt{a^2+b^2+c^2}$ is not an integer:

2, 5, 1   - 6, which is wrong, should be sqrt(30)
7, 6, 6   - 7, which is wrong, should be 11, here's what I think
- it violate the clues set by the problem. The problem state
- the smallest ONE, and the bigger TWO.


P.S. I tagged it under elementary number theory, if you think it's better off to be somewhere else, comment below. Need more information? Comment below. Thanks!

-
What about $a=7,b=6,c=6$, where $\sqrt{a^2 + b^2 + c^2} = 11$ and $a+b-c = 7$? –  Cocopuffs Jan 2 at 14:29
EDIT: correct how m and n should be, both missed the square root sign. –  Shane Hsu Jan 2 at 14:29
@Cocopuffs There should be only one smallest, as the problem DID NOT state. It is a badly written problem, and another badly written explanation by me. –  Shane Hsu Jan 2 at 14:31
Very well. Take $a=12, b=9, c=8$ where $\sqrt{a^2 + b^2 + c^2} = 17$ and $a+b-c = 13$. –  Cocopuffs Jan 2 at 14:32
@Cocopuffs Ya, I really want to say it's a false positive. But, since I can't. You win? The problem still remain though, why is it correct under some condition? –  Shane Hsu Jan 2 at 14:37

In your question you say: So the problem gives me an additional condition: the difference between the minimum of the three and the bigger other two is perfect squares.

That said, if c is the smallest of the two. $b−c$ and $a−c$ will both be perfect squares. And the answer itself is an integer, which means $a^2+b^2+c^2$ is also a perfect square.

The second paragraph contradicts the first-the first only guarantees that one of $a-c$ and $b-c$ is a square. If the numbers are as you say, you will still get overflow of $(a+b-c)^2$, which is greater than $a^2$

Your derivation is incorrect. $2m^2n^2=2(a-c)^2(b-c)^2=2(a^2-2ac+c^2)(b^2-2bc+c^2)$ which has a term $2a^2b^2$

-
Yes, you are correct, I mistyped how m and n should be. And yes, I thought $a+b-c$ will overflow, but as the solution submitted is marked as accepted, I guess it's the design of the question. –  Shane Hsu Jan 2 at 14:28
@ShaneHsu: Under Organize the two, you lost a term $2c^2$. You need to add that to the left. It is not true that $2(a-c)(b-c)$ is zero. –  Ross Millikan Jan 2 at 14:33
@ThomasAndrews: True, but the left side has $-c^2$ and the right has $+c^2$ –  Ross Millikan Jan 2 at 14:39
@RossMillikan I'm just objecting to this line: $2m^2n^2=2(a-c)^2(b-c)^2=2(a^2-2ac+c^2)(b^2-2bc+c^2)$. I assumed that was your correction of the original post, but it is wrong. –  Thomas Andrews Jan 2 at 14:42
@ThomasAndrews: Yes, that was a correction to the original post. In it, we had $m=a-c$ –  Ross Millikan Jan 2 at 14:43