7

I have tried using modulo arithmetic with $\bmod9$. However, I have found that it doesn't always help. It seems that for most numbers the parity of their digit sum is the same as the parity of the number $\bmod9$. But this is not always true. For example: $19 = 1\mod9$, but $1+9=10$ which is even. If someone could explain this as well, that would very helpful.

msh210
  • 3,860
  • 1
    It's no surprise that mod 9 doesn't help. Hint. Try starting with the numbers from 1-10. Then think about the numbers from 11-100, in groups or 10. Try to generalize. – Ethan Bolker Nov 19 '16 at 17:46
  • @EthanBolker Why is it no surprise? – John Smith Nov 19 '16 at 17:47
  • 1
    @JohnSmith Because the notion of "even" or "odd" doesn't exist modulo $9$. Specifically, we have, for instance, $10\equiv 1$. – Arthur Nov 19 '16 at 17:49
  • Because calculating mod 9 gives you the digit sum mod 9, and knowing a number mod 9 says nothing about whether it's even or odd. Probably your first though was "try mod 9" because you knew the divisibility test for 9. But first thoughts don't always work. – Ethan Bolker Nov 19 '16 at 17:51
  • I did think to use mod9 because I connected it with solving "sums of digits" problems, yes. But I also tried the pairing method below, and others. And I am aware first thoughts don't always work. – John Smith Nov 19 '16 at 17:54

3 Answers3

12

Between $0$ and $9$ (inclusive), exactly half has even sum of digits, and exactly half has odd sum of digits. Same with $10$-$19$. Same with $20$-$29$. And so on. So for numbers from $0$ to $9\,999$ (inclusive) there are equally many numbers with even and odd sum of digits.

Arthur
  • 199,419
  • My range doesn't include 0 so would this mean there are more odd sums? – John Smith Nov 19 '16 at 17:55
  • 1
    But there's 10000 as well – John Smith Nov 19 '16 at 17:56
  • And this is useful, thank you, but would it be possible to be slightly more rigorous please? – John Smith Nov 19 '16 at 17:57
  • 3
    @JohnSmith In regards to making it more rigorous, you could maybe try proving it by induction. I.e. adapting Arthur's answer to show that, regardless of the preceding digits, the numbers from $\ldots\mathrm{x}\mathrm{x}0$ to $\ldots\mathrm{x}\mathrm{x}9$ will be alternating even and odd. It avoids having to use modular arithmetic too. – Jam Nov 19 '16 at 18:04
  • 5
    @JohnSmith I guess you meant something slightly more detailed. An answer doesn't need to involve calculations or implications to be rigorous, and I don't think this one have any lack of it. –  Nov 19 '16 at 18:05
  • 3
    Since the question was about 1 to 10000, you are missing the even digit sum 0, and you add the odd digit sum 10,000, so you have 5,001 numbers with odd digit sum and 4,999 with even digit sum. – gnasher729 Nov 19 '16 at 20:04
1

Picking a number from $0$ to $10^n-1$ means choosing $n$ digits, where leading zeroes are allowed. Leading zeroes do not affect the parity of the digit sum. There are as many ($5$) even digits as odd ones, so the amount of numbers with an even/odd digit sum is $5^n$ times the number of binary numbers of length $n$ with an even/odd digit sum, i.e. with an even/odd number of nonzero digits, which are the same, as there are as many subsets of $\{1,\ldots,n\}$ of even/odd size, see e.g. Alternating sum of binomial coefficients: given $n \in \mathbb N$, prove $\sum^n_{k=0}(-1)^k {n \choose k} = 0$.

Finally, we leave out $0$ and include $10^n$, so there are $2$ more numbers with an odd digit sum.

Bart Michels
  • 26,355
1

If n is even, then one of n and n+1 has an even sum of digits, and one has an odd sum. So if a range of numbers starts with an even and ends with an odd number, then there are equally many numbers with even and with odd digit sum.

If the first number is odd, and/or the last number is even, then these need to be handled separately. In this case the first number 1 is odd and has odd digit sum, the last number 10,000 is even and has also odd digit sum, so there are two numbers more with odd than with even digit sum from 1 to 10,000.

This can be applied easily to any other range, for example the numbers from 1234 to 5678: The first one is even (ignore it), the last one is even and 5678 has even digit sum, so there is one number more with an even sum of digits.

gnasher729
  • 10,113
  • Good answer, if it would focus on the parity of digit sum and omit mention of the parity of the integer, which is irrelevant. – msh210 Nov 19 '16 at 20:33
  • Nice observation. It corresponds to the map in this answer to a related question I mentioned in my answer: http://math.stackexchange.com/a/611771/43288 – Bart Michels Nov 19 '16 at 20:51