Sudal's Garage

Project Euler 9 본문

Programming/Project Euler - python

Project Euler 9

_Sudal 2019. 2. 6. 15:29

Question: 



A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a2 + b2 = c2

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

문제:

다음 피타고라스 정리를 만족하면서 a < b < c 관계를 만족하는 세 자연수 abc를 피타고라스 수라고 부른다.

a2 + b2 = c2


예를 들어, 32 + 42 = 9 + 16 = 25 = 52 가 있다.

a + b + c = 1000를 만족하면서 피타고라스 수인 세 자연수가 유일하게 존재한다. 그 수들의 곱 abc의 값을 구하여라.


Solution:

1
2
3
4
5
6
7
8
9
10
11
12
isit = False
for c in range(1,1000):
    for b in range(1,c):
        a = 1000 - c - b
        if a < b and b < c and a < c:
            if a ** 2 + b ** 2 == c ** 2:
                isit = True
                print('a: {}\nb: {}\nc: {}\nproduct: {}'.format(a,b,c,a*b*c))
        if isit == True:
            break
    if isit == True:
        break
cs





'Programming > Project Euler - python' 카테고리의 다른 글

Project Euler 11  (0) 2019.02.26
Project Euler 10  (0) 2019.02.16
Project Euler 8  (0) 2019.02.05
Project Euler 6  (0) 2019.01.30
Project Euler 5  (0) 2019.01.30