Determine a general formula (in terms of n) for the sum of the first n positive integers that are not divisible by 5.

Well, let s be the number of numbers that need to be skipped to get n that are not multiples of 5. Then we sum up the first n+s numbers, and subtract out the first s multiples of 5.

This equals (n+s)(n+s+1)/2 - 5s(s+1)/2

And s = floor(n/4)

So, for example, if n = 13, then s = 3

sum = 16*17/2 - 5*3*4/2 = 136 - 30 = 106

This is the right answer, as (1+2+3+4)+(6+7+8+9)+(11+12+13+14)+16 = 10+30+50+16 = 106

The previous post, if I followed it correctly, has q = 3 and r = 0,

for a total of 13*14/2 + 3*(6 - 1) = 91 + 15 = 106,

so the two formulae yield the same result, at least in this case