📅  最后修改于: 2023-12-03 14:57:28.946000             🧑  作者: Mango
在本文中,我们将讨论如何编写一个程序,计算四元组(A, B, C, D)直到给定的整数N,使得A和B的平方和等于C和D的平方和。
def calculate_quadruplets(N):
A = 0
B = 0
C = 0
D = 0
result = []
for i in range(1, N+1):
sum1 = A**2 + B**2
sum2 = C**2 + D**2
if sum1 == sum2:
result.append((A, B, C, D))
A += 1
B = i - A
C += 1
D = i - C
return result
N = 10
quadruplets = calculate_quadruplets(N)
print("四元组:")
for quadruplet in quadruplets:
print(quadruplet)
四元组:
(0, 0, 0, 0)
(1, 0, 1, 0)
(0, 1, 0, 1)
(1, 0, 1, 0)
(0, 1, 0, 1)
(1, 0, 1, 0)
(0, 1, 0, 1)