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

Numbers whose difference between Sum of digits at even location and Sum of digits at odd location is 1... Let us call those numbers that satisfy these condition to be "GOOD NUMBERS"

For ex..) the number 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 given a 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...

ie)if my range is from 1 to 100,without actually considering each number from 1 to 100 and finding the sum of its even positioned digits,and sum of odd positioned digits and then thier difference is there a way by which we could tell how many numbers on doing the above mentioned operation would yield a value 1....

What i figured out was all good numbers if divided by 11 would yield a remainder 10 but the converse is not true...for eg.)109 if divided by 11 would yield a remainder 10...but then it is not a good number..(0)- (9+1) = - 10....

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.....

-

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.
@Jayanth: The example N and M I gave are for a four digit number. $N(2,9)=9$ says there are $9$ different combinations of numbers that can go in the first and third positions that sum to $9$. These are $18, 27, 36, \ldots$. If the odd positions sum to $9$, the even positions need to sum to $8$. Since $M(2,8)=9$ there are $9\cdot 9=81$ four digit numbers where the odd positions sum to $9$ and the even ones sum to $8$. You need to sum over all the possibilities for the sum of the odds. –  Ross Millikan Sep 19 '12 at 16:51