# Evaluate $m(S)$.

Let $S$ be the set of all $n$-digit ($n > 1$) numbers $N$ such that:

1. $N$ is formed from digits $1,2,4,5$ and the difference between any two consecutive digits of $N$ is 1.

2. $N$ is divisible by 11.

Denote $m(S)$ the arithmetic mean of all numbers in $S$. Evaluate $m(S)$.

-
Did you mean to exclude $3$ from your set? Under the current conditions, all your numbers would have to look like 1212121... or 21212121... or 4545454... or 545454... And do you mean $N$ to include such numbers with any number of digits, or do you mean for a fixed $n$? – rschwieb Oct 4 '12 at 15:42
Nevermind, I guess you mean for a fixed $n$. Otherwise $S$ would be infinite... – rschwieb Oct 4 '12 at 15:45
For $n\leq2$ and $4\leq n\leq 8$ the set $S$ is empty, so the arithmetic mean is undefined in these (and probably some other) cases. – Marc van Leeuwen Oct 4 '12 at 15:58

By (1), the numbers are either have only 1 and 2 or 4 and 5 as digits.

More precisely, if $n=2k$ is even, then $$N=c\cdot \frac{10^n-1}{99}$$ with $c\in\{12,21,45,54\}$. Since the $c$ are not divisible by 11, $N$ is divisible by 11 only if $10^n\equiv 1\pmod {121}$, i.e. $n$ is a multiple of 22. In that case $$m(S)= \frac{12+21+45+54}4\cdot \frac{10^n-1}{99} = \frac{10^n-1}3.$$ However, if $n$ is not a multiple of 22, then $S$ is empty and $m(S)$ is undefined.

And if $n=2k+1$ is odd, then $$\tag1N=10c\cdot \frac{10^{2k}-1}{99}+d$$ with $c\in\{12,21,45,54\}$ and $d=c\bmod 10$. A quick check shows that $\frac{10^{2k}-1}{99}\equiv k\pmod{11}$. Hence we are looking for solutions of $d\equiv kc\pmod{11}$. This leads to $$k\equiv \begin{cases}2&c=12\\10&c=21\\5&c=45\\7&c=54\end{cases}$$ We conclude that $S$ contains only one numer $N$, given by $(1)$, if $k\equiv 2, 5, 7, 10\pmod {11}$; then $m(S)$ is also this $N$. In all other cases, $m(S)$ is undefined.

Here's a quick proof that $\frac{10^{2k}-1}{99}\equiv k\pmod{11}$: Let $a_k=\frac{10^{2k}-1}{99}$. The statement is clearly true for $k=0$, i.e. $a_k=0$. The rest follows by induction from $a_{k+1}=100a_k+1\equiv a_k+1\equiv k+1\pmod {11}$.

-
Your proof was awesome. Can you say me how did you get the idea of doing like this in the first place.Thanks in advance. – Phani Raj Oct 4 '12 at 16:33
You are doing something wrong in the second part, since $k=1$ (so $n=3$) gives the solution $N=121$ that you miss. It would seem to me that you should have $d=(\lfloor c/10\rfloor)\bmod 10$ rather than $d=c\bmod 10$. – Marc van Leeuwen Oct 5 '12 at 7:01

If N has odd no.of digits i.e, $(2k-1)$digits.Then for the sequence $4545...4(2k-1 digits)$, k should be of the form $5-11r,r\in \mathbb{Z}$.(divisibility rule of 11)

for the sequence $5454...5(2k-1 digits)$, k should be of the form $11r-4,r\in \mathbb{Z}$.

for the sequence $1212...1(2k-1 digits)$, k should be of the form $2-11r,r\in \mathbb{Z}$.

for the sequence $2121...2(2k-1 digits)$, k should be of the form $11r-1,r\in \mathbb{Z}$.

You have to take all the possible values of $k$ which are positive. For a given $n$ check which conditions it satisfies and take the mean according to it. Then $k$ should be of the form $11r,r\in \mathbb{Z}$

If N has even no.of digits i.e, $(2k)$digits.Then You have to take all the possible values of $k$ which are positive. For a given $n$ check which conditions it satisfies and take the mean according to it.

-
You didn't take into account divisibility. Even for $n=3$ this is wrong. – EuYu Oct 4 '12 at 15:58
No, for $n=3$ it is clearly $121$. For $n=9$ it is $454545454$. – Marc van Leeuwen Oct 4 '12 at 15:59
sorry.i forgot that condtion – Phani Raj Oct 4 '12 at 16:01