[Math] Sum of $n$ consecutive numbers divided by $n$

number theory

I was trying to write a poker program yesterday, and trying to figure out a way to tell the computer how to detect a straight. I realized that if you add $5$ consecutive numbers and divide by $5$, you'll get no remainder. I tried for $6$ consecutive numbers, but it didn't work. It turns out it only works for odd numbers. Really silly question, but does this 'method' have a name? Has it been proven that for all odd $n$, the sum of any $n$ consecutive numbers divided by $n$ yields a remainder of zero?

Best Answer

Yes, If $n=2k+1$, write the numbers as

$a - k, a-(k-1), \dots,a-1, a, a + 1, \dots, a+(k-1), a+k$

Adding gives you $na$ which is divisible by $n$.

Try something similar for even $n =2m$ and you see that the sum is $m \mod n$, which is not divisible by $n$.

Related Question