[Math] The sum of all numbers between 1 and 1000 (inclusive) that are divisible by 3 or 5, but not both

elementary-number-theory

I found a problem that asked to calculate the sums of all numbers between $1$ and $1000$ (inclusive) that are divisible by $3$ or $5$, but not both.

I immediately thought of Gauss which made me smile but didn't get me anywhere. I thought of using the summation, but I still have no idea how to do this but by brute force. Any ideas?

I'll likely need fairly explicit explanations. I'm an undergrad who has just learned basic proving techniques and is just starting to apply it to abstract algebra, analysis, etc.

Best Answer

I have a proposal for the solution of the more general problem for the sum of like powers of arbitrary natural exponents. This is based on the Faulhaber-/Bernoulli-polynomials.
Consider that polynomials organized in a matrix (which I called "Gp" when I found them). Each row r contain the coefficients for the r 'th Faulhaber polynomial. I introduce also the notation for a "Vandermondevector" -type: $ V(x) = \text{columnvector}(1,x,x^2,x^3,...)$; if I use it as diagonalmatrix I prefix it with a "d" like $\ ^dV(x)$.
The matrix $Gp$ begins like $$ \Tiny \begin{bmatrix} 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1/2 & 1/2 & 0 & 0 & 0 & 0 \\ 0 & 1/6 & 1/2 & 1/3 & 0 & 0 & 0 \\ 0 & 0 & 1/4 & 1/2 & 1/4 & 0 & 0 \\ 0 & -1/30 & 0 & 1/3 & 1/2 & 1/5 & 0 \\ 0 & 0 & -1/12 & 0 & 5/12 & 1/2 & 1/6 \end{bmatrix}$$ and along the rows we see the coefficients for the integrals of the Bernoulli-polynomials. Using that in a matrix-formula we get $$ Gp \cdot V(m) = V(1) + V(2) + V(3) + ... + V(m) $$ To have the sum $V(3)+V(6)+...+V(3m)$ instead it suffices to write $$ ( ^dV(3) \cdot Gp \cdot \ ^dV(1/3))\cdot V(3m) = V(3) + V(6) + V(9) + ... + V(3m) $$ Thus, introducing a matrix-valued-function $$H(x) \overset{\text{def}}= \ ^dV(x) \cdot Gp \cdot \ ^dV(1/x) $$ allows to write $$ \begin{eqnarray} H(3) \cdot V(3m) &=& V(3)+V(6)+...+V(15)+ ... +V(3m) \\ H(5) \cdot V(5m) &=& V(5)+V(10)+...V(15) + ... +V(5m) \\ H(15) \cdot V(15m) &=& V(15)+V(30)+... +V(15m) \\ \end{eqnarray} $$ and finally, with a notation for the highest integer equal or below n divisible by m for convenience $$ n:m \overset{\text{def}}{=} m \cdot \Big\lfloor { n \over m} \Big\rfloor $$ we can write $$ S_{3,5}(m) = H(3)\cdot V( m:3) + H(5) \cdot V(m:5) - 2H(15) \cdot V(m:15 ) $$ For $m=1000$ we get the vector of solutions for the sums with exponents 0,1,2,3,4,5,6,7 $$ \begin{matrix} S_{3,5}(1000) &=& \small \begin{bmatrix}\begin{array} {rll} 401 &\Tiny = 3^0+6^0+...+999^0 + 5^0+10^0+...+1000^0 -2(15^0+30^0+...+990^0)\\ 201003 &\Tiny = 3+6+...+999 + 5+10+15+...+1000 -2(15+30+...+990)\\ 134335661 &\Tiny = 3^2+6^2+...+999^2 + 5^2+10^2+...+1000^2 -2(15^2+30^20+...+990^2)\\ 101003482917 \\ 81004632555017 \\ 67672443055260693 \\ 58149771588796814081 \\ 51008046700741091931597 \end{array} \end{bmatrix} \end{matrix}$$ The formulae are $$ \begin{matrix} S_{3,5}&=& \small \begin{bmatrix} \begin{array} {l} \frac 13 m_3+\frac 15 m_5- \frac 2{15} m_{15} \\ \frac 1 6 m_3^2 +\frac 12 m_3 + \frac 1{10} m_5^2 +\frac 12 m_5 - \frac 1{15} m_{15}^2- m_{15} \\ \frac 1 9 m_3^3+ \frac 12 m_3^2+\frac 12 m_3 +\frac 1{15}m_5^3+\frac 12 m_5^2+ \frac 56m_5 -\frac 2{45} m_{15}^3-m_{15}^2-5 m_{15} \\ \vdots \end{array} \end{bmatrix} \end{matrix}$$ where the $m_k$ denote the $(m:k) = k \cdot \lfloor \frac mk \rfloor$.

You're interested in the second row $S_{3,5;1}$.
With $m=1000 $ inserted you get $$\small \frac 16 m_3^2+\frac 12 m_3+ \frac 1{10}m_5^2+\frac 12 m_5-\frac 1{15} m_{15}^2-m_{15} $$ and with $m_3=999,m_5=1000,m_{15}=990$ inserted you get $$ S_{3,5;1}(1000) = \frac 12(\frac 1 3 999^2+ 999 + \frac 1 5 1000^2+ 1000 -\frac 2{15} 990^2-2 \cdot 990) $$ which is finally $$ S_{3,5;1}(1000) = 201003 $$

One can arrive at the last formula for the second row by far simpler means (as shown in other answers); however for the general problem: to get the rows for the sums-of-like-powers with higher exponents, I think this (known) array of Faulhaber-polynomials (handled by the matrix-formulae) should be the general and most convenient one.


(as someone remarked already: this (without the removal of the multiples of 15) is also the "project-euler-problem-1", but much generalized)