8
$\begingroup$

The number 3025 when split in the middle gives us 30 and 25. 30+25= 55. The square of 55 is 3025.

What other 4 digits numbers have this property i.e. when the 4 digit number is split in the middle, the 2 numbers are added to each other and the resulting number is squared, we get back the original number?

Looking for an intuitive method to solve this.

Bonus: What method can we use to find 2 digit, 6 digit, 8 digit numbers with the above property? For example, Marius in his answer has shown that 494209 is one such number. (494+209)^2=494209.

Source: Challenging puzzles and perplexing mathematical problems by Dudeney

P.S: The book has given a solution which I am unable to understand. I will post the solution after everybody stops attempting this question.

$\endgroup$
3
  • 2
    $\begingroup$ oeis.org/A238237 lists the numbers with this exact property. $\endgroup$
    – Bubbler
    Commented May 28 at 10:13
  • $\begingroup$ @Bubbler: there are only 3 such 4-digit numbers; that sequence lists solutions with other (even) lengths too. I edited the title to specify "4-digit". $\endgroup$
    – smci
    Commented May 30 at 4:09
  • $\begingroup$ Those numbers are called Kaprekar numbers: oeis.org/A006886 $\endgroup$
    – ThomasL
    Commented May 30 at 18:53

3 Answers 3

19
$\begingroup$

daw's (now deleted) answer contains a good starting point. Namely:

Setting the equation $(a + b)^2 = 100a + b$ and changing it to $(a + b - 50)^2 = 2500 - 99b$. Here, $a$ and $b$ are the first and second halves of the four-digit number we want to find. The range of $a$ and $b$ are $10 \le a \le 99$ and $0 \le b \le 99$.

Now,

substitute $a + b - 50 = x$ to simplify to $2500 - 99b = x^2$. Then we get $99b = 2500 - x^2 = (50-x)(50+x)$. The range of $x$ is $-50 \le x \le 50$ (to not make $b$ on the left side negative); since the equation in question is symmetric, we can limit to $0 \le x \le 50$ and then substitute both $x$ and $-x$ later.

Let's apply some elementary number theory:

Since $99b$ is a multiple of 11, either $50-x$ or $50+x$ must be too. $$ 11 | 50-x \Rightarrow x = 6, 17, 28, 39, 50 \\ 11 | 50+x \Rightarrow x = 5, 16, 27, 38, 49 $$

The same can be said about 9. Note that $50-x$ and $50+x$ cannot be multiples of 3 at the same time, so one of them must be a multiple of 9. $$ 9 | 50-x \Rightarrow x = 5, 14, 23, 32, 41, 50 \\ 9 | 50+x \Rightarrow x = 4, 13, 22, 31, 40, 49 $$

Take the intersection of two results and we get

$$x = 5, 49, 50$$ $$\require{cancel} x = \pm 5 \Rightarrow b = 25, a = 20, 30$$ $$x = \pm 49 \Rightarrow b = 1, a = \cancel{0}, 98$$ $$x = \pm 50 \Rightarrow b = 0, a = \cancel{0}, \cancel{100}$$

resulting in the answers

2025, 3025, and 9801.

For 2-digit numbers, the equation to solve is

$$9b = (5-x)(5+x)$$

and the only way to satisfy this is

$$x = \pm 4 \Rightarrow b = 1, a = \cancel{0}, 8 \Rightarrow 81$$

For 6-digit numbers:

$$999b = (500-x)(500+x)$$ Since $999 = 3^3 \times 37$, one of $500-x$ and $500+x$ is a multiple of 27, and the same for 37. This gives $x \equiv 13 \text{ or } 14 \operatorname{mod} 27$ and $x \equiv 18 \text{ or } 19 \operatorname{mod} 37$.

and it can get tedious to list out all the possible candidates. More number theory to the rescue:

By Chinese remainder theorem, you can combine the modular equations modulo 27 and 37 into one modular equation modulo 999. Since the modulus is larger than the range of $x$ (between 0 and 500), we can simply remove the "modulo" part. The results are: $$x \equiv 13 \operatorname{mod} 27, x \equiv 18 \operatorname{mod} 37 \Rightarrow x = 499, b = 1, a = \cancel{0}, 998 \\ x \equiv 13 \operatorname{mod} 27, x \equiv 19 \operatorname{mod} 37 \Rightarrow x = \cancel{796} \\ x \equiv 14 \operatorname{mod} 27, x \equiv 18 \operatorname{mod} 37 \Rightarrow x = 203, b = 209, a = \cancel{88}, 494 \\ x \equiv 14 \operatorname{mod} 27, x \equiv 19 \operatorname{mod} 37 \Rightarrow x = \cancel{500}$$ giving the two answers 494209 and 998001.

I'm pretty sure the same method can be used for more number of digits. As the number of distinct prime factors of $99\cdots 99$ increases, the number of combinations of equations to solve increases as well, so you will eventually need a computer program for the job; nevertheless, it should find all answers much more quickly than brute force.

$\endgroup$
3
  • $\begingroup$ Why does $x$ have to be $\leq 50$? Why can't it be up to $148$? $\endgroup$ Commented May 28 at 23:00
  • 1
    $\begingroup$ @DanielHatton Then $b$ is negative in the equation $99b = 2500 - x^2$, which is not what we want. $\endgroup$
    – Bubbler
    Commented May 28 at 23:05
  • $\begingroup$ Yep, I see it, thanks. $\endgroup$ Commented May 28 at 23:06
8
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ 2025 is missing from the list. $\endgroup$
    – Bubbler
    Commented May 28 at 8:12
  • $\begingroup$ yep...copy-paste error. thanks $\endgroup$
    – Marius
    Commented May 28 at 8:16
8
$\begingroup$

We are looking for $2k$-digit numbers $N^2$ such that adding their first half to their second half yields $N$.

This process is almost exactly a reduction modulo $10^k-1$, with the exception that the sum of the halves is not further reduced.

This implies that it would be better to turn our attention to $N$ itself.

$N$ satisfies $N(N-1) \equiv 0 \mod 10^k-1$. Since $N$ and $N-1$ are coprime, we can find the unitary factors $D$ of $10^k-1$ and solve the system $\begin{array}{rl}\\N\equiv 0\mod&D\\N\equiv 1\mod&\frac{10^k-1}{D}\end{array}$ to find each corresponding solution, noting that if $n$ is a solution for $D$, then $10^k-n$ is a solution for $\frac{10^k-1}{D}$.

And here are the solutions:

 (a,b) is shorthand for "0 modulo a and 1 modulo b"
k = 1
(1,9) N = 1 is too small
(9,1) N = 9 yields 81
k = 2
(1,99) N = 1 is too small
(9,11) N = 45 yields 2025
(11,9) N = 55 yields 3025
(99,1) N = 99 yields 9801
k = 3
(1,999) N = 1 is too small
(27,37) N = 297 is too small
(37,27) N = 703 yields 494209
(999,1) N = 999 yields 998001
k = 4
(1,9999) N = 1 is too small
(9,1111) N = 2223 is too small
(11,909) N = 2728 is too small
(99,101) N = 4950 yields 24502500
(101,99) N = 5050 yields 25502500
(909,11) N = 7272 yields 52881984
(1111,9) N = 7777 yields 60481729
(9999,1) N = 9999 yields 99980001
etc.

and a Python script that can very rapidly generate the valid squares, provided you give it the appropriate factorizations of $10^k-1$:

def euclid(a,b): #returns the least multiple of a congruent to 1 modulo b
    A = 1; B = a//b; D = a%b
    while D > 1:
        if b%D: k = b//D+1; A = (A*k)%b; B = (B*k+1)%a; D -= b%D
        else: k = a//D+1; A = (A*k-1)%b; B = (B*k)%a; D -= a%D
    return A*a

for k,L in enumerate([[9],[9,11],[27,37],[9,11,101],[9,41,271],[27,7,11,13,37],
          [9,239,4649],[9,11,73,101,137],[81,37,333667],
          [9,11,41,271,9091],[9,21649,513239],[27,7,11,13,37,101,9901]]):
    #prime-power decompositions of 10^k - 1 for k from 1 to 12
    res = []
    for i in range(2**len(L)):
        prod, div = 1, 1
        for n in L:
            if i%2: prod *= n
            else: div *= n
            i //= 2
        N = euclid(prod,div)
        if N**2 >= 10**(2*k+1): res += [[N**2,N,prod,div]]
    for i in sorted(res): print(*i)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.