# Finding $N$ which has distinct digits, divisibility by $5$

Suppose $N$ is an $n$-digit positive integer such that

$\bullet$ all the $n$-digits are distinct; and

$\bullet$ the sum of any three consecutive digits is divisible by $5$.

Prove that $n$ is at most $6$. Further, show that starting with any digit one can find a six-digit number with these properties.

It is my question .Let the first digit be '$a$' and the second be '$b$' then the third become '$5n-(a+b)$. Then I found the fourth digit is $a$ , which is not possible.I can't found any way. Somebody please help me.

• I edited, but is that what you meant? – S.C.B. Feb 25 '17 at 12:08
• Well, $1046$ is a four digit example...$10465$ is a five digit example... – lulu Feb 25 '17 at 12:10
• @S.C.B. No you edit is useless,I don't mean it!! – Sufaid Saleel Feb 25 '17 at 12:10
• @SufaidSaleel What do you mean? You really meant $n$ is at most $6$? But $6$ is not an integer that satisfies the property..... – S.C.B. Feb 25 '17 at 12:10
• @S.C.B. I said that N is the integer and n is the number of digits of N – Sufaid Saleel Feb 25 '17 at 12:13

For any four consecutive digits, $\ldots abcd\ldots$ both $a+b+c$ and $b+c+d$ are multiples of $5$. It follows that $a\equiv d\pmod 5$. If $n>6$, consider seven conseutive digits: $\ldots abcdefg\ldots$. As above, we ave $a\equiv d\equiv g\pmod 5$, but for each remainder $\bmod 5$, there are only two candidate digits.
Starting from almost any three-digit number with distinct digits an digit sum divisible by $5$, we can use the above restrictions to extend it to a four, five, and six digit example. For example, from $460$ we get to $5460$, then to $15460$ and to $915460$. Only with a "bad start" such as $163$ with two digits differing by $5$, we get to $8163$ and are stuck (or with $136$, we are stuck immediately).