Determine a general formula (in terms of n) for the sum of the first n positive integers that are not divisible by 5.
This may not be the most succinct expression but I believe it works. The motivation was that this would be related to the sequence of triangular numbers, except after every group of four integers there would be an additional increment.
f(n) = n(n+1)/2 + floor((n1)/4) * [ 2*floor((n1)/4) + (n1)mod 4  1]
To make it a bit easier to read, for (n1)/4 let q be the quotient and r be the remainder (such that n1 = 4q + r). Then
f(n) = n(n+1)/2 + q * (2q + r  1)
Edited on March 18, 2014, 10:07 am

Posted by tomarken
on 20140318 10:05:52 