美文网首页
Project Euler #1.Multiples of 3

Project Euler #1.Multiples of 3

作者: 善法 | 来源:发表于2018-07-04 22:16 被阅读0次

    原题链接: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

          本文链接:https://www.haomeiwen.com/subject/qqwyuftx.html