[Math] Difference between sum of even positioned digits and sum of odd positioned digits in a number is equal to 1

number theory

A "Good Number" is a number whose difference between the sum of its digits at even places and the sum of digits at odd places is $1.$

For example, $234563$ is a good number.

Digits at odd location are $3,5,3$ (unit place is location 1).
Digits at even location are $2,4,6$.
Diff $=(2+4+6)-(3+5+3)=12-11 = 1$.

And 123456 is not a good number, because
diff=$(5+3+1)-(2+4+6)=9-12 = -3$.

Good Numbers from 1 to 100 are $$10,21,32,43,54,65,76,87,98$$
So my question is, in a given range, like 1 to 100 or 1 to 1000 for
instance is there a way to find out how many numbers in the range are
good numbers without actually having to test each number?

I figured out that all good numbers when divided by 11 would yield a
remainder 10. But the converse is not true (if 109 is divided by
11 would yield a remainder 10, but it is not a good number).

I also came across a similar question where given a
range we need to find the numbers that on finding the difference
between Sum of digits at even location and Sum of digits at odd
location would yield a prime number. Since finding difference between the
sum of even and odd positioned digits is the base for both the
problems it would be of great help if someone could help me with
this…

Thanks in advance…..

Best Answer

Several simplifications are possible. First, consider numbers with the same number of digits at a given time, so the range should be 100-999 instead of 1-1000. You have already established the result from 1-99, and if you really want 1-1000 you could just notice that 1000 needs to be counted.

It looks like when you say difference, you mean signed difference: 23 doesn't count because the sum of the evens is one less than the sum of the odds.

Consider the case of $n$ digits with $n$ even ($n$ odd will be similar). Let $m=\frac n2$. You are interested in how many ways there are to get $m$ numbers in the range $0$ to $9$ to make a given sum. So you can define $N(m,p$) as the number of ways to have $m$ numbers in this range add up to $p$ for the odd places. There is some perturbation for the odd places as you don't allow a leading zero. In this case, $N(2,1)=1, N(2,2)=2, \ldots N(2,9)=9, N(2,10)=9 , \ldots N(2,18)=1$ Then define $M(m,p)$ similarly for the even places, $M(2,0)=1, M(2,1)=2, \ldots M(2,9)=10, M(2,10)=9 , \ldots M(2,18)=1$. Now you can find $\sum N(m,i)M(m,i-1)$ to get the total.

Related Question