LoginSignup
1
1

More than 5 years have passed since last update.

Python3でProject Eulerを解く

Last updated at Posted at 2018-07-08

はじめに

Python3を勉強するためにProject Eulerの問題を順番に解いていきます.

Problem1

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

同じようにして, 1000 未満の 3 か 5 の倍数になっている数字の合計を求めよ.

hoge.py
ans = 0
for cnt in range(1,1000):
    if cnt%3 ==0 or cnt%5 == 0:
        ans += cnt
print(ans)
1
1
3

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
1
1