The math way (added second)
Let's say k is the number of digits...
Write the equation like
$ (x + y)^2 = 10^{\frac{k}{2}} x + y $
Transform this to a quadratic equation and try to find y based on x
$ y^2 + 2xy - y + x^2 - 10 ^{\frac{k}{2}} x + x^2 = 0$
Solving this based on y you get
$ y = \frac{-2x+1 + \sqrt{4 \times 10^\frac{k}{2}x - 4x + 1}}{2}$
I know there is an option to get + or - before the square root, but if we use minus we get y as a negative number.
Now you need to make sure that $ 4 \times 10^\frac{k}{2}x - 4x + 1$ is a perfect square where x has k digits.
That's as a far as I could go.
(Maybe now I can change the code below to optimize it and make it run faster)
Solution using computers (added initially)
I know this may not count as an answer because I cheated a but with a some code (in my defense, I started writing this before the no-computers tag was added), but here it is just in case....
<?php
function findNumbers(int $digits)
{
if ($digits % 2 === 1 || $digits <=0) {
return [];
}
$numbers = [];
for ($i = pow(10, $digits - 1); $i <= pow(10, $digits) - 1; $i++) {
$one = substr((string)$i, 0, $digits / 2);
$two = substr((string)$i, $digits / 2);
if (pow($one + $two, 2) === $i) {
$numbers[] = $i;
}
}
return $numbers;
}
print_r(findNumbers(2));
You can run it on https://onlinephp.io/
It does not work for 8 digits because it takes to long.
but here are the results (ran it on my computer):
2 digits: 81
4 digits: 2025 3025 9801
6 digits: 494209 998001
8 digits: 24502500 25502500 52881984 60481729 99980001
EDIT to the code after applying "the math way".
<?php
function findNumbers(int $k)
{
$epsilon = 0.00000001;
if ($k % 2 === 1 || $k <=0) {
return [];
}
$numbers = [];
for ($i = pow(10, $k/2 - 1); $i< pow(10, $k/2); $i++) {
$root = sqrt(4 * pow(10, $k/2) * $i - 4 *$i + 1);
if (abs($root - (int)$root) < $epsilon) {
$numbers[] = pow(10, $k/2) * $i + (1 - 2*$i + (int)$root) / 2;
}
}
return $numbers;
}
print_r(findNumber(2)); //replace 2 with 4, 6, 8 to get other values.
Same numbers pop up but now they appear faster.
Bonus here are the numbers for:
10 digits: 6049417284 6832014336 9048004641 9999800001
12 digits: 101558217124, 108878221089, 123448227904, 127194229449, 152344237969, 213018248521, 217930248900, 249500250000, 250500250000, 284270248900, 289940248521, 371718237969, 413908229449, 420744227904, 448944221089, 464194217124, 626480165025, 660790152100, 669420148761, 725650126201, 734694122449, 923594037444, 989444005264, 999998000001
14 digits: 19753082469136, 24284602499481, 25725782499481, 30864202469136, 87841600588225, 99999980000001