# Moving last digit to first

Is it possible to find all positive integers $n$ such that if we move its last digit to the first digit, we get $2n$? I.e $2(a_m\cdot 10^m+\ldots +a_0)=a_0\cdot 10^m+a_m\cdot 10^{m-1}\cdots+a_1$

-
Some simple playing around shows that this is equivalent to $2(a \cdot 10 + b) = b \cdot 10^k + a$, where $10^{k-1} \le a < 10^k$, and hence, $19 a = (10^k-2) b$. Therefore, a neccessary condition is that $b$ is a multiple of 19, and $a$ is even. Since $1 \le b \le 9$, this should answer the question. –  Johannes Kloos Apr 30 '12 at 12:01
@Johannes, why must $b$ be a multiple of 19? Why can't $10^k-2$ be a multiple of 19? –  Gerry Myerson Apr 30 '12 at 12:43
Um, you're right. It can. –  Johannes Kloos Apr 30 '12 at 12:52
OEIS A146088 gives the first ten of an infinite sequence –  Henry Apr 30 '12 at 13:03

There are at least two ways to solve this. One is the straightforward algebraic way given by Johannes Kloos and Gerry Myerson. The other is trickier but easier.

Let's guess—just guess—that $2n$ might begin with, say, 6, and see what that would imply. If we divide $2n$ by 2, using the usual short division algorithm, we see at once that $n$ must then begin with 3:

      3 ...      6
-------------
2 ) 6??? ...


But the digits of the dividend, $2n$, are exactly the same as the digits of the quotient, $n$, except that the quotient has the 6 on the end instead of on the beginning. So the second digit of the dividend must be 3:

      3 ...      6
-------------
2 ) 63?? ...


So continuing with short division, the second digit of the quotient (and the third digit of the dividend) is 1:

      31 ...     6
-------------
2 ) 631? ...


This time the short division algorithm says that since there was a remainder of 1 when we divided by 2, the next digit of the quotient is 11/2 = 5:

      315 ...    6
-------------
2 ) 6315 ...


Continuing in this way quickly yields:

      315789473684210526
-------------------
2 ) 631578947368421052


When we get to a 6 in the quotient and no remainder from the previous division, we can stop, and we have an answer: 315789473684210526 × 2 = 631578947368421052.

All the solutions can be found this way, by selecting some initial digit other than 6. Had we selected 2, we would have gotten the smallest solution, $2n$ = 210526315789473684, and $n=$105263157894736842. (Starting with 1 yields the degenerate solution $2n=$105263157894736842, $n=$052631578947368421; starting with 0 yields the even more degenerate solution $2n=n=0$.)

Had we decided not to stop the first time the initial digit repeated, but to continue dividing until the next stopping point, we would have gotten a solution twice as long; there are arbitrarily long solutions.

-
Incidentally, solutions in radices other than base 10 are sometimes much simpler. For example, in base 8, 25×2=52, and in base 3, 1012×2=2101. The algebraic technique will show you where the simple solutions are. –  MJD Apr 30 '12 at 13:10

Rewrite the equation as $$19(10^{m-1}a_m+10^{m-2}a_{m-1}+\cdots+a_1)=(10^m-2)a_0$$ and you get $19$ divides $10^m-2$. The smallest solution is $m=17$. So you get $$10^{m-1}a_m+10^{m-2}a_{m-1}+\cdots+a_1=5263157894736842a_0$$. Taking $a_0=2$ you get the solution $$105263157894736842$$

You can get others solutions by taking other values of $a_0$ and/or taking $m=17+18t$, $t=1,2,3,\dots$. Many references will be found by typing 105263157894736842 into Google.

-
"The smallest solution is $m=17$" is something of a rabbit from a hat, since finding such $m$ is a discrete logarithm problem, and discrete logarithms are believed to be hard to find. I do not know any elementary method for finding this one other than trial multiplication mod 19. –  MJD Apr 30 '12 at 17:16
@Mark: Finding discrete logarithms modulo 19 is not hard (by exhaustive search even). Finding discrete logarithmg modulo a 100-digit prime OTOH... If you want something quicker for the present case: $$10^{18}\equiv1\pmod{19}$$ by little Fermat. Combine that with $2\cdot10=20\equiv1\pmod{19}$ and get $$10^{18}\equiv 2\cdot 10\pmod{19}.$$ Hmm... –  Jyrki Lahtonen Apr 30 '12 at 21:21
@Jykri Yes, I did not mean to say that this particular question was hard, only that it should have been accompanied by some explanation. –  MJD May 1 '12 at 14:26