The Pythagorean theorem, which is the basis of the famous three-square theorem, is in a right triangle.
The number of combinations in which this (a.b, c) is a natural number is called the Pythagorean triple. The genius Pythagoras, who was active in ancient BC, described this combination as the following formula:
I realized that I could express it as.
However, while this formula can show that there are an infinite number of Pythagorean triples, it is not exhaustive.
So is there a comprehensive formula?
The first answer is said to remain in the 7th century Indian literature.
As m> n
After all, Indian mathematics is advancing! !!
def Pythagoras(n :int) -> list:
answer = []
answer.append((n**2-1)/2)
answer.append(n)
answer.append((n**2+1)/2)
return answer
for i in range(1,100,2):
answer = Pythagoras(i)
for i in range(0,3):
answer[i] = int(answer[i])
print(answer)
a | b | c |
---|---|---|
4 | 3 | 5 |
12 | 5 | 13 |
24 | 7 | 25 |
40 | 9 | 41 |
60 | 11 | 61 |
84 | 13 | 85 |
112 | 15 | 113 |
144 | 17 | 145 |
180 | 19 | 181 |
220 | 21 | 221 |
264 | 23 | 265 |
312 | 25 | 313 |
If it is a small combination, you can see that (6, 8, 10) has been skipped.
# m > n
def Pythagoras_2(k :int, m :int, n: int) -> list:
answer = []
answer.append(k*(m**2 - n**2))
answer.append(2*k*m*n)
answer.append(k*(m**2 + n**2))
return answer
for k in range(1,5):
for m in range(1,5):
for n in range(1,10):
if m <= n :
break
print(Pythagoras_2(k,m,n))
a | b | c |
---|---|---|
3 | 4 | 5 |
8 | 6 | 10 |
5 | 12 | 13 |
15 | 8 | 17 |
12 | 16 | 20 |
7 | 24 | 25 |
6 | 8 | 10 |
16 | 12 | 20 |
10 | 24 | 26 |
30 | 16 | 34 |
24 | 32 | 40 |
14 | 48 | 50 |
9 | 12 | 15 |
24 | 18 | 30 |
15 | 36 | 39 |
45 | 24 | 51 |
36 | 48 | 60 |
21 | 72 | 75 |
12 | 16 | 20 |
32 | 24 | 40 |
20 | 48 | 52 |
60 | 32 | 68 |
48 | 64 | 80 |
28 | 96 | 100 |
The combination of Pythagorean triples can be comprehensively expressed.
Recommended Posts