I am writing this answer because you said that you were trying a guess and check method. Computers are good at this. A decent algorithm is to have two integers $n_x$ and $n_y$ which start at 1. Then, calculate x by doing $2n_x^2$ and y by doing $5n_y^5$. Check if they are equal; if they are, you found your answer. If not, whichever of $x$ and $y$ are lower, increment that $n$ value (i.e., if $x < y$, then increment $n_x$). Recalculate $x$ and $y$ and repeat until they are the same.
Here is an example implementation in Python using generators:
class SpecialSquareGenerator:
def __init__(self, n=0):
self.n = n
def __iter__(self):
return self
def __next__(self):
self.n += 1
return self.n, 2*(self.n**2)
class SpecialFifthGenerator:
def __init__(self, n=0):
self.n = n
def __iter__(self):
return self
def __next__(self):
self.n += 1
return self.n, 5*(self.n**5)
def special_square():
n = 0;
ss = SpecialSquareGenerator()
sf = SpecialFifthGenerator()
nx, x = next(ss)
ny, y = next(sf)
print("{0}: {1}\t{2}: {3}".format(nx, x, ny, y))
while True:
if (x == y): return x
if x < y:
nx, x = next(ss)
else:
ny, y = next(sf)
print("{0}: {1}\t{2}: {3}".format(nx, x, ny, y))
if __name__ == "__main__":
print(special_square())
Running it returns the right answer:
gns-mac1:sandbox gns$ python3 special_square.py
1: 2 1: 5
2: 8 1: 5
2: 8 2: 160
3: 18 2: 160
...(output omitted)
494: 488072 10: 500000
495: 490050 10: 500000
496: 492032 10: 500000
497: 494018 10: 500000
498: 496008 10: 500000
499: 498002 10: 500000
500: 500000 10: 500000
500000
Of course, the mathematical approach is better for understanding the problem. But if you need to guess and check, then computers are the tool for that.
P.S.
There is another way to exhaustively search for the solution. You can take sequential numbers and try dividing them by 2 (or 5) and then taking the square root (or fifth root) and then checking if that result is an integer for both operations. There are two downsides to this approach:
- You have to decide if a floating point number is supposed to represent an integer. This is hard for computers and language implementations to do because computers only have a fixed set of digits to represent floating point numbers.
- The search space is greater (by order of $n^2$). So that means that you should expect to take longer to reach the same answer, given the same hardware.
P.S.S.
There are faster ways to implement both my algorithm, and the other I mentioned in the postscript. For example, you can double $n$ each time and then when you overshoot, use binary search in the space between the last $n$ and the one that overshot.