0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2019-08-27

####ピタゴラス数(ピタゴラスの定理を満たす自然数)とは a < b < c で以下の式を満たす数の組である.

####a2 + b2 = c2

#####例えば, 32 + 42 = 9 + 16 = 25 = 52 である.

####a + b + c = 1000 となるピタゴラスの三つ組が一つだけ存在する.
####これらの積 abc を計算しなさい.

problem8は**こちら**から

つまり、aa + bb == c*c and a + b + c == 1000ということのはず

a,b,cはそれぞれ1000以下のはずだからrange(1000)でいいはず

かつ、a + b + c == 1000だということは

kotae = 0
for a in range(1,1000):
    for b in range(a,1000):
        for c in range(b,1000):
            if a*a + b*b == c*c and a + b + c == 1000:
                kotae = a*b*c
print(kotae)   

31875000

正解---

0
1
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?