# Find the 9-digit no. containing digits $1$ to $9$ exactly once, such that $n$ divides the no. formed by first $n$ digits.

If a nine-digit number is formed using each of the digits $1,2,3,...,9$ exactly once, for $n = 1,2,3,...,9$, $n$ divides the first $n$-digits of the number, Find the number.

I can think that the fifth digit will be $5$, as there is no other option, and also that I do not have to think of making the no. divisible by $9$, as the sum of its digits will always be equal to $45$. I have also applied the divisibility rules of $2,4,6,8$ and can say that the second, fourth, sixth and eighth should be even, which implies that others are odd. But I am unable to pile up all the findings leading to the solution.

• This is remarkably similar to one of Conway's Pi Day pizza problems. – Chris May 19 '17 at 4:55
• Yes, you are right – ami_ba May 19 '17 at 5:04
• If we label each of the digits by position, then so far I get $3|(d_1 d_2 d_3)$, $4|(d_3 d_4)$, $6|(d_5 d_6 d_7)$, and $8|(d_7 d_8)$. Not sure if this is the right direction to go in.... – Chris May 19 '17 at 5:09
• ofc. I also got these, but after that? These are just math. rep. of what I said – ami_ba May 19 '17 at 5:11
• Well, for one thing there are few two-digit numbers divisible by $8$, so I'm looking at that right now. – Chris May 19 '17 at 5:13

The fifth digit is $5$ as you said.

The second, fourth, sixth, and eighth digits are even, as you said.

The fourth digit must be $2$ or $6$ since the third digit is odd.

The fourth, fifth, and sixth digits must sum to a multiple of $3$, so the sixth digit must be $8$ or $4$ respectively (depending on whether the fourth digit is $2$ or $6$ respectively).

The 3-digit number formed by the sixth, seventh, and eighth digits must be divisible by $8$. Since this looks like "$8ab$" or "$4ab$" where $a$ is odd, the eighth digit must be $6$ or $2$, whichever is not used by the fourth digit.

So, the second digit must be $4$ or $8$, whichever is not used by the sixth digit.

So far, we have two choices: $$x_1 4 x_3 2 5 8 x_7 6 x_9$$ $$y_1 8 y_3 6 5 4 y_7 2 y_9$$

We just need to put $1$, $3$, $7$, and $9$ in the blanks to make the first three digits add up to a multiple of $3$, and the last three digits add up to a multiple of $3$.

Let's try the first choice. The first three digits are either $147$ or $741$. In either case, the divisibility by $8$ forces the last three digits to be $963$. Finally, we check divisibility by $7$, to decide between $147$ or $741$ in the first three digits, but neither work.

So we are left with the second case. The divisibility by $8$ means the seventh digit $y_7$ is either $3$ or $7$. If it is $3$, we can try either $789$, $189$, $987$, or $981$ for the first three digits and see if the divisibility by $7$ holds; none of them work.

So we must have $y_7=7$, and we can try $183$, $189$, $381$ and $981$ for the first three digits; $381$ satisfies the divisibility by $7$. Thus the answer is $$381654729.$$