Special Pythagorean triplet

Problem 9

A Pythagorean triplet is a set of three natural numbers, a Project Euler Problem9 b Project Euler Problem9 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.

 
The code is simple:
a = 0
b = 0
c = 0
totalSum = 1000
cMax = int(totalSum/2)
cMin = int(totalSum/3)
aMax = cMin
c = cMax
while c > cMin:
    b = c - 1
    while b > 1:
        a = totalSum - c - b
        if a > b or a < 1 or a > aMax:
            break
        if a*a + b*b == c*c:
            print(a, b, c)
            print(a*b*c)
            break
        b -= 1
    c -= 1

  

相关文章:

  • 2021-07-28
  • 2021-08-03
  • 2022-02-02
  • 2021-05-27
  • 2021-04-14
  • 2021-08-19
  • 2021-12-08
  • 2021-05-30
猜你喜欢
  • 2021-06-07
  • 2022-12-23
  • 2021-12-01
  • 2021-10-01
  • 2021-05-22
  • 2022-02-09
  • 2021-09-05
相关资源
相似解决方案