[?] Calculate this simple equation 2^x * 5^y = 5000 ?

Hello, I’, trying to find the correct way to calculate a “rather” simple equation

2^x * 5^y = 5000

, where x, y would be integers and the program would start with x=1, y=1, check for correctness and if incorrect, add an integer to x, check again… for so long until it finds the right x and y (x=3,y=4). I have no idea how to solve that, my programming skills are very bad. Any help much appreciated!

In Mathematica, looping is inefficient, It’s better to do it all at once.

In[17]:= Table[{x, y, 2^x*5^y == 5000}, {x, 0, 5}, {y, 0, 5}]

Out[17]= {{{0, 0, False}, {0, 1, False}, {0, 2, False}, {0, 3, 
   False}, {0, 4, False}, {0, 5, False}}, {{1, 0, False}, {1, 1, 
   False}, {1, 2, False}, {1, 3, False}, {1, 4, False}, {1, 5, 
   False}}, {{2, 0, False}, {2, 1, False}, {2, 2, False}, {2, 3, 
   False}, {2, 4, False}, {2, 5, False}}, {{3, 0, False}, {3, 1, 
   False}, {3, 2, False}, {3, 3, False}, {3, 4, True}, {3, 5, 
   False}}, {{4, 0, False}, {4, 1, False}, {4, 2, False}, {4, 3, 
   False}, {4, 4, False}, {4, 5, False}}, {{5, 0, False}, {5, 1, 
   False}, {5, 2, False}, {5, 3, False}, {5, 4, False}, {5, 5,
   False}}}

It also possible to select out the answer.

In[15]:=  Select[Flatten [Table[{x, y}, {x, 0, 5}, {y, 0, 12}], 1], 
 2^#[[1]]*5^#[[2]] == 5000 &]

Out[15]= {{3, 4}}

Use FindInstance

FindInstance[2^x*5^y == 5000 && x > 0 && y > 0, {x, y}, Integers]

(*  {{x -> 3, y -> 4}}  *)

Or use Solve

Solve[2^x*5^y == 5000 && x > 0 && y > 0, {x, y}, Integers]

(*  {{x -> 3, y -> 4}}  *)

Or Reduce

xmax = x /. Solve[(2^x*5^y == 5000 /. y -> 1) && x > 0, x][[1]] // Floor

(*  9  *)

Reduce[2^x*5^y == 5000 && 0 < x <= xmax && y > 0, {x, y}, Integers] // ToRules

(*  {x -> 3, y -> 4}  *)

Alternatively,

ymax = y /. Solve[(2^x*5^y == 5000 /. x -> 1) && y > 0, y][[1]] // Floor

(*  4  *)

Reduce[2^x*5^y == 5000 && 0 < x && 0 < y <= ymax, {x, y}, Integers] // ToRules

(*  {x -> 3, y -> 4}  *)

I’d take advantage of unique factorization of integers for this.

FactorInteger[5000] /. {{2, x_} :> x, {5, y_} :> y}

(* Out[270]= {3, 4} *)