LoginSignup
9
7

More than 5 years have passed since last update.

Python で Project Euler #1「3と5の倍数」

Last updated at Posted at 2014-11-05

Problem 1 「3と5の倍数」

10未満の自然数のうち, 3 もしくは 5 の倍数になっているものは 3, 5, 6, 9 の4つがあり, これらの合計は 23 になる.
同じようにして, 1000 未満の 3 か 5 の倍数になっている数字の合計を求めよ.

Python
seq = range(1000)

result = 0
for i in seq:
  if i % 3 == 0 or i % 5 == 0:
    result += i
print result
print result == 233168
結果
233168
True
9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7