Sum multiples of 3 and 5: Difference between revisions
Content added Content deleted
Line 3,976: | Line 3,976: | ||
≫ |
≫ |
||
===Efficient solution=== |
===Efficient solution=== |
||
This is a |
This is a fast approach to calculate the sum for higher values of n, taking into account that: |
||
# the sum of multiples of 3 and 5 is the sum of multiples of 3 plus the sum of multiples of 5, minus the sum of multiples of 15 to remove double counting |
# the sum of multiples of 3 and 5 is the sum of multiples of 3 plus the sum of multiples of 5, minus the sum of multiples of 15 to remove double counting |
||
# the sum of multiples of m being < n is equal to m*(1+2+ ... k) with k =[n/m] |
# the sum of multiples of m being < n is equal to m*(1+2+ ... k) with k =[n/m] |