What is the sum of the multiples of 5 or 8 but not both?
Question
Considering only the integers from 1 to 1000 inclusive, find the sum of those integers which are either multiples of 5 (i.e., 5, 10, 15, …) or multiples of 8 (i.e., 8, 16, 24, …) but are not multiples of both 5 and 8.
Solution
We need (5+10+15…+1000)+(8+16+24+…+1000)−2(40+80+…+1000).
We’ll use the formula that the sum of the first n terms of an arithmetic progression is 2n(u1+un),
where un is the nth term. So here we have
2200(5+1000)+2125(8+1000)−2×225(40+1000)=137500.
Alternatively, we have
(5+10+15…+1000)+(8+16+24+…+1000)−2(40+80+…+1000)
=5(1+2+3…+200)+8(1+2+3+…+125)−2×40(1+2+3+…+25).
Now we know 1+2+…+n=2n(n+1), so this becomes
52200(201)+82125(126)−80225(26)=137500.