0

I was recently asked a question in an interview & have been unable to crack it, after my own efforts have failed & Google not showing any results , I am posting it here so that anyone else may also try their hand on it .

Given the equation:

a (a + b) = c - 120

where a,b & c are unequal prime numbers, find a, b & c.

I know I must use some property of the prime numbers to reduce the problem to a simpler one, but I can't think of one. Any suggestions/solutions will be appreciated.

The best I could come up with is that :

  • There may be multiple solutions to it. My first approach was a brute force search for 3 prime numbers that solved this equations. (I know , totally useless)
  • The second approach was a refinement of the first, to modify the equation to a (a + b) - 120 = c. So now we reduce our brute force variables to just a & b & check if the LHS is prime no for the selected a & b. (If c were to be large, finding out whether the LHS is a prime would take away the advantage gained by reducing the variables from 3 to 2.)

So you see, I am not really going anywhere.

torrential coding
  • 1,755
  • 2
  • 24
  • 34
  • The best I could come up with is that : 1) There may be multiple solutions to it . My first approach was a brute force search for 3 prime no's that solved this equations. (i know , totally useless) 2)The second approach was a refinement of the first, to modify the equation to a(a+b)-120=c. So now we reduce our brute force variables to just a & b & check if the LHS is prime no for the selected a & b.(If c were to be large , finding out whether the LHS is a prime would take away the advantage gained by reducing the variables from 3 to 2.) So you see , i am not really going anywhere. – user1460604 Jun 16 '12 at 12:56
  • I note that you can rearrange that to `a^2+ba+(120-c)=0`, which is a quadratic on a which happens to have a couple of unknown coefficients (the coefficients are `(1, b, 120-c)`). Is that useful? Can you plug that into the standard quadratic formula and get anything of any use? Can you factorise it differently? – Tom Anderson Jun 16 '12 at 13:08
  • How many solutions are there if `a` and `b` are both odd? How many solutions are there if `a` is 2? – Luke Woodward Jun 16 '12 at 13:12
  • @TomAnderson hmm... nice, but i now have 3 equations with a ,a^2,b,b^2,c . what next? I still think i must somehow use the fact that the numbers are prime to reduce the complexity of the problem. – user1460604 Jun 16 '12 at 15:08
  • 2
    What a bizarre question. What was the position and where, if you don't mind my asking? Wolfram? :) – cheeken Jun 16 '12 at 15:18

2 Answers2

2

all primes are odd, except 2 - (1)

all primes are positive - (2)

odd - even = odd (3)

(1), (2) => c > 120 and c is odd - (4)

odd * odd = odd - (5)

(3), (4), (5) => c-120 is odd => a(a+b) is odd - (6)

even + odd = odd - (7)

(6) => a is odd, a+b is odd (8)

(7), (8) => b is even => b = 2

So, we have a^2 + 2a = c-120

I couldn't go any further

scriptin
  • 3,060
  • 1
  • 24
  • 33
2

Let's stipulate that c > 120. That implies c != 2. So the RHS is odd.

Therefore the LHS has to be odd, so a (a + b) has to be odd. So a is odd, and a+b is odd. This only works out if b is even, and b is prime, so b = 2.

So we have a(a+2) = c - 120.

So a^2 + 2a + (120-c) = 0

Using the quadratic formula, solving for a, we get

[-2 +- sqrt(2^2 - 4 * 1 * (120 - c))] / 2

= -1 +- sqrt(1 - (120-c))

= -1 + sqrt(c - 119)

So we need a prime number c, so that c - 119 is a perfect square.

This is a quick calculation with a table of primes.

The smallest one I can find is c = 263, so a = 11, b = 2

It looks like c=443, a=17, b=2 also works.

There don't appear to be any other c values below 1000.

Possibly there are many, many others.

Michael
  • 66
  • 1
  • No need to search for squares, just check that `c=a(a+2)+120` is prime: `[(a,c) | a<-primes, let c=a*(a+2)+120, isPrime c]` produces `[(11,263),(17,443),(29,1019),(47,2423),(59,3719),(71,5303),(89,8219),(107,11783),(137,19163), ... (2999,9000119),(3119,9734519), ... (122777,15074437403),(122819,15084752519), ...`. – Will Ness Jun 17 '12 at 08:48
  • `... (316067,99898980743),(316241,100009002683), ... (547499,299756250119),(547871,300163728503), ... (1000037,1000076001563),(1000199,1000400040119), ...` . BTW just searching for squares as you describe is insufficient, because there's no guarantee for `a` to be prime, calculated that way back from `c`, only to be odd. Indeed there are such non-prime `a`s: `(77,6203),(119,14519),(287,83063)...`. – Will Ness Jun 17 '12 at 09:13