👩‍💻 알고리즘/🐢 PYTHON

for문 피타고라스

오브 🧙‍♂️ 2023. 9. 12. 23:18

비효율적인 알고리즘

for a in range(1, 400):
    for b in range(1, 400):
        for c in range(1, 400):
            if a * a +  b * b == c * c and a < b < c and a + b + c == 400:
                print(a * b * c)

효율적인 알고리즘

for a in range(1,400):
    for b in range(1,400):
        c = 400 - a - b
        if a * a + b * b == c * c and a < b < c :
            print( a * b * c )