LoginSignup
2
0

More than 3 years have passed since last update.

【Python】 プロジェクトオイラー Problem 5

Last updated at Posted at 2019-07-02
2520 は 1 から 10 の数字の全ての整数で割り切れる数字であり, そのような数字の中では最小の値である
では, 1 から 20 までの整数全てで割り切れる数字の中で最小の正の数はいくらになるか

Problem4はこちらから

なるほど、つまりif文で2から20まで割りきれたときのみ変数に出力すればいいと

とりあえず上限を5億にしてやってみる

for a in range(500000000):
    if a % 2 == 0 :
        if a % 3== 0 :
            if a % 4 == 0 :
                if a % 5 == 0 :
                    if a % 6 == 0 :
                        if a % 7 == 0 :
                            if a % 8 == 0 :
                                if a % 9 == 0 :
                                    if a % 10 == 0 :
                                        if a % 11 == 0 :
                                            if a % 12 == 0 :
                                                if a % 13 == 0 :
                                                    if a % 14 == 0 :
                                                        if a % 15 == 0 :
                                                            if a % 16 == 0 :
                                                                if a % 17 == 0 :
                                                                    if a % 18 == 0 :
                                                                        if a % 19 == 0 :
                                                                            if a % 20 == 0 :
                                                                                b = a
                                                                                print(b)

0
232792560
465585120

[http://kingyojima.net/pje/005.html:title]

正解は232792560とのことなので上限を3億にしてみる

さすがにもう一度は書き込みませんが上限を3億にしておわりです

はっきり言って全く参考にならないと思いますがこういうやつもいると思ってください...

problem6はこちらから

2
0
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
2
0