Project Euler #1.Multiples of 3 and 5

原题链接:https://projecteuler.net/problem=1

题目描述

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.


题目分析:求出1000以内3和5的倍数的个数(不重复)
解题方法:
\lfloor 999 / 3 \rfloor = 333
\lfloor 999 / 5 \rfloor = 199
\lfloor 999 / 15 \rfloor = 66
sum = 3 \times \frac{333\times(1+333)}{2} + 5 \times \frac{199\times(1+199)}{2} - 15 \times \frac{66\times(1+66)}{2} = 233168

你可能感兴趣的:(Project Euler #1.Multiples of 3 and 5)