第 1 题: 3 或 5 的倍数

Problem 1: Multiples of 3 or 5

题目

3 或 5 的倍数

在小于 1010 的自然数中,3355 的倍数有 33556699 ,这些数之和是 2323

求小于 10001000 的自然数中所有 3355 的倍数之和。

Multiples of 3 or 5

If we list all the natural numbers below 1010 that are multiples of 33 or 55, we get 33 , 55, 66 and 99. The sum of these multiples is 2323.

Find the sum of all the multiples of 33 or 55 below 10001000.

解题方法

用集合 AA 表示大于 11 小于 1000100033 的倍数。

显然集合 AA 中的数据是首项是 33 ,公差是 33 的等差数列的前 10003⌊\frac {1000}{3}⌋ 项。

用集合 BB 表示大于 11 小于 1000100055 的倍数。

显然集合 BB 中的数据是首项是 55 ,公差是 55 的等差数列的前 10005⌊\frac {1000}{5}⌋ 项。

用集合 CC 表示大于 11 小于 100010001515 的倍数。

显然集合 CC 中的数据是首项是 1515 ,公差是 1515 的等差数列的前 100015⌊\frac {1000}{15}⌋ 项,且 C=ABC=A \cap B

根据容斥原理,显然

xABx=aAa+bBbcCc\sum_{x \in { A \cup B}} x = \sum_{a \in A} a + \sum_{b \in B} b-\sum_{c \in C}c

参考代码

1
print((3+999)*(1000//3)/2 + (5+995)*(1000//5)/2 - (15+990)*(1000//15)/2)

正确答案

答案
233168

参考链接

0%