Q:

Is there any other way of getting a function from this piece of code?

I have this pseudocode
function mysterious(N):
    count = 0
    for i = 0 to N:
        if (i mod 3 == 0):
            count = count + i
    return count

The problem ask for the expression that returns this function using N or in terms of N
The best I have done is $\sum\limits_{i=0}^n i \bmod 3$
Is there any better way to express the function of this code?
I know the code returns the sum of the numbers divisible by 3

A:

Hint: Use the formula
$$ \sum_{i=1}^k i = \frac{k(k+1)}{2}. $$
You can consider first the case that $N$ is a multiple of $3$.
Further hint: Use the formula
$$ \sum_{i=1}^k 3i = 3\frac{k(k+1)}{2}. $$
When $N$ is a multiple of $3$, a good choice of $k$ is $N/3$. More generally, you should choose $k = \lfloor N/3 \rfloor$.

