# Swapping the first and last digits of an integer

Take any n-digit integer (n > 1) and interchange its first and last digits. If neither of these is 0, and they are different, does it happen infinitely often that the resulting number is a multiple of the original one?

If so, for each n (say up to n=20, unless a general solution is provided), what is the largest and smallest numbers for which this happens?

• I could not find a single occurrence to think on. Do you have any example? :P Jun 19 '20 at 16:50
• I hope this doesn't count as a clue, but to save people some work, there are no 2-digit numbers with this property. Jun 19 '20 at 18:23
• I don't think I've ever seen a number with the stated property - but I think it's universal that the difference between the number and the result of the described operation will be a multiple of 9 (i.e., ab......cd - db......ca is always 9 × k). Jun 19 '20 at 18:42
• My computer thinks there is no such number up to 1000000000. Jun 19 '20 at 19:26
• Dear commenters: what happened to not putting spoilers in the comments? Also: math.stackexchange.com/questions/2860037/…
– Bass
Jun 19 '20 at 21:49

Suppose the first digit is a and the last digit is c. (The rest of the number can be denoted as b.)
Then our original number is $$a\cdot 10^{n-1}+b\cdot 10 + c$$ and after swapping the digits it is $$c\cdot 10^{n-1}+b\cdot 10 + a$$.
The question asks whether there are $$a,b,c$$ such that $$\frac{c\cdot 10^{n-1}+b\cdot 10 + a}{a\cdot 10^{n-1}+b\cdot 10 + c} = N$$ for some integer $$N > 1$$. Clearly $$N < 10$$ as they have the same number of digits as well. Also, $$c > a$$.
Subtracting one from the above equation, we get $$\frac{(10^{n-1}-1)(c-a)}{a\cdot 10^{n-1}+b\cdot 10 + c} = N-1$$, i.e. $$\frac{(10^{n-1}-1)(c-a)}{N-1} = a\cdot 10^{n-1}+b\cdot 10 + c$$.

Now we proceed via casework:

We have the bounds that $$N-1 \in \{1,2,3,4,5,6,7,8\}$$.
If $$N-1 \in \{1,2,4,5,8\}$$, then $$10^{n-1}-1$$ shares no factors with $$N-1$$ so if the LHS is an integer, it must be a factor of $$10^{n-1}-1$$. Since $$a$$ should be smaller than $$c$$, our options are: $$19\dots98$$, $$29\dots97$$, $$39\dots96$$, $$49\dots95$$, corresponding to $$\frac{c-a}{N-1}$$ values of $$2,3,4,5$$ but at the same time $$c-a$$ values of $$7,5,3,1$$. At no point are the right numbers a multiple of the left numbers, so this rules out this possibility.
If $$N-1 \in \{3,6\}$$, then $$10^{n-1}-1$$ could absorb a factor of $$3$$. This gives our options as $$13\dots32$$, $$16\dots65$$, $$19\dots98$$, $$26\dots64$$, $$29\dots97$$, corresponding to $$\frac{3(c-a)}{N-1}$$ values of $$4,5,6,8,9$$ and $$c-a$$ values of $$1,4,7,2,5$$. But similarly, the right hand numbers are never a multiple of the left hand numbers.
If $$N-1 = 7$$, then $$10^{n-1}-1$$ could absorb a factor of $$7$$. We're pretty restricted in this case - $$(c-a)$$ must be $$8$$, because otherwise the LHS has $$n-1$$ digits versus the RHS $$n$$ digits. $$7|10^{n-1}-1$$ only when $$6|n-1$$ for which the result is $$142857\dots142857$$. Adding $$9\dots9$$ to this, we get $$1142857\dots142856$$, which has $$c-a$$ value of $$5$$, which is not $$8$$. So this concludes our casework and therefore there are no solutions.

• I like how we used very different methods to come to the same conclusion. Jun 19 '20 at 21:52

I don't think there are any solutions

To see this. Let's try to figure out what possible first and last digits are. Let those digits be $$x$$ and $$y$$ where $$x > y$$. That means the numbers would be $$xd_0d_1\ldots y$$ (this is concatenation not multiplication) and $$yd_0d_1\ldots x$$ where $$(yd_0d_1\ldots x) * k = (xd_0d_1\ldots y)$$.

We can draw a few useful facts from this. $$\left \lfloor{x\div k}\right \rfloor= y$$ (looking at the most significant digit) and $$x*k = y\text{ }(\text{mod }10)$$ (looking at the least significant digit). So, let's see what combinations qualify. For the table below the numbers at the top are different values for $$x$$ and the left numbers are $$k$$. Solving the two equations for $$y$$ give the left and right numbers in each cell.

  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |
--+-----------------------------------------------+
2 | 1 4 | 1 6 | 2 8 | 2 0 | 3 2 | 3 4 | 4 6 | 4 8 |
3 | 0 6 | 1 9 | 1 2 | 1 5 | 2 8 | 2 1 | 2 4 | 3 7 |
4 | 0 8 | 0 2 | 1 6 | 1 0 | 1 4 | 1 8 | 2 2 | 2 6 |
5 | 0 0 | 0 5 | 0 0 | 1 5 | 1 0 | 1 5 | 1 0 | 1 5 |
6 | 0 2 | 0 8 | 0 4 | 0 0 | 1 6 | 1 2 | 1 8 | 1 4 |
7 | 0 4 | 0 1 | 0 8 | 0 5 | 0 2 | 1 9 | 1 6 | 1 3 |
8 | 0 6 | 0 4 | 0 2 | 0 0 | 0 8 | 0 6 | 1 4 | 1 2 |
9 | 0 8 | 0 7 | 0 6 | 0 5 | 0 4 | 0 3 | 0 2 | 1 1 |

Continuing...

Looking at the table above we know that the valid combinations must result in the same number (also it can't be 0 because 0 is not valid for $$y$$). This leaves us two options. $$x=8, y=2, k=4$$ or $$x=9, y=1, k=9$$.

However, in both of these cases $$x$$ is divisible by $$k$$ which is a problem. Looking back at the equation $$(yd_0d_1\ldots x) * k = (xd_0d_1\ldots y)$$, we know that $$(d_0d_1\ldots x) * k = (d_0d_1\ldots y)$$ as long as $$y*k = x$$. But we know that $$(d_0d_1\ldots x) > (d_0d_1\ldots y)$$ which means there are no solutions for $$(d_0d_1\ldots x) * k = (d_0d_1\ldots y)$$ and therefore no solutions to this puzzle.

• I couldn't figure out the formatting to make it work in one spoiler Jun 19 '20 at 19:59