All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Sum Divisibility Dilemma (Posted on 2014-03-18)
Determine a general formula (in terms of n) for the sum of the first n positive integers that are not divisible by 5.

 No Solution Yet Submitted by K Sengupta No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 Solution, might be able to improve | Comment 1 of 6

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((n-1)/4) * [ 2*floor((n-1)/4) + (n-1)mod 4 - 1]

To make it a bit easier to read, for (n-1)/4 let q be the quotient and r be the remainder (such that n-1 = 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 2014-03-18 10:05:52

 Search: Search body:
Forums (0)