Jean,
This is going to be a bit tough over email, but here goes.
The main trick here is to realize that you can write the multiples of k as k*i and sum from 1 to floor(n/k) to get the sum of the multiples of k from 1 to n. For example, the sum of the multiples of 3 can be written as:
sum(3*i, 1, n / 3)
Because of distributivity, we can pull the 3 out of the sum and get
3 * sum(i, 1, n / 3)
which is pretty cool because now we have a sum from 1 to n/3. We can now apply the formula that gives us the sum of numbers from 1 to m:
m * (m + 1) / 2
and substitute m = n / 3. This gives us:
3 * n / 3 * [(n / 3) + 1] / 2
More generally, we can write the sum of the multiples of k as:
k * n / k * [(n/k) + 1] / 2
and simplify to:
n/2 * [(n/k) + 1]
Now you can write out the 3 sums in this form and simplify to an analytic answer for a closed form answer to the problem:
n/2 * [(n / 3) + 1] + n/2 * [(n/5) + 1] - n/2 * [(n/15) + 1]
Factor out the n/2:
n/2 * [(n/3) + (n/5) - (n/15) + (1 + 1 - 1)]
We can now give a common base to the n/k fractions and simplify:
n/2 * [ 5n/15 + 3n/15 - n/15 + 1] = n/2 * [7n/15 + 1]
Which is the closed form solution you were hoping for.
All that said, don't trust my math and work it out by hand for yourself. I likely made some mistakes through this procedure :).
Thanks,
Arjun