Seth's answer is the right one. I'm leaving this answer here to help elaborate on why the answer to 128 8 512
is 4
because people seem to be having trouble with that.
A geometric progression's elements can be written in the form c*b^n
where b
is the number you're looking for (b
is also necessarily greater than 1), c
is a constant and n
is some arbritrary number.
So the best bet is to start with the smallest number, factorize it and look at all possible solutions to writing it in the c*b^n
form, then using that b
on the remaining numbers. Return the largest result that works.
So for your examples:
125 5 625
Start with 5. 5 is prime, so it can be written in only one way: 5 = 1*5^1
. So your b
is 5. You can stop now, assuming you know the row is in fact geometric. If you need to determine whether it's geometric then test that b
on the remaining numbers.
128 8 512
8
can be written in more than one way: 8 = 1*8^1
, 8 = 2*2^2
, 8 = 2*4^1
, 8 = 4*2^1
. So you have three possible values for b
, with a few different options for c
. Try the biggest first. 8
doesn't work. Try 4
. It works! 128 = 2*4^3
and 512 = 2*4^4
. So b
is 4
and c
is 2
.
3 15 375
This one is a bit mean because the first number is prime but isn't b
, it's c
. So you'll need to make sure that if your first b
-candidate doesn't work on the remaining numbers you have to look at the next smallest number and decompose it. So here you'd decompose 15: 15 = 15*?^0
(degenerate case), 15 = 3*5^1
, 15 = 5*3^1
, 15 = 1*15^1
. The answer is 5, and 3 = 3*5^0
, so it works out.