完美立方

描述

费马大定理断言:当整数n>2时,关于a,b,c的方程an=bn+cn没有正整数解。该定理被提出后,历经三百多年,经历多人猜想辩证,最终在1995年被英国数学家安德鲁·怀尔斯证明。当然,可以找到大于1的4个整数满足完美立方等式:a3=b3+c3+d3(例如123=63+83+103)。编写一个程序,对于任意给定的正整数N(N ≤100),寻找所有的四元组(a,b,c,d),满足a3=b3+c3+d3,其中1<a,b,c,d≤N。

 1 n = int(input()) # n范围内的立方数
 2 
 3 list_cube = [0] # 用于存储立方数的列表
 4 
 5 for i in range(1, n + 1):
 6 
 7     list_cube.append(i * i * i)
 8 
 9 for a in range(6, n + 1):
10     for b in range(2, a - 1):
11         if list_cube[a] < (list_cube[b] + list_cube[b + 1] + list_cube[b + 2]):
12             break
13         for c in range(b + 1, a):
14             if list_cube[a] < (list_cube[b] + list_cube[c] + list_cube[c + 1]):
15                 break
16             for d in range(c + 1, a):
17                 if list_cube[a] == (list_cube[b] + list_cube[c] + list_cube[d]):
18                     print("Cube = %d,Tripe = (%d,%d,%d)" % (a, b, c, d))
View Code

相关文章:

  • 2021-08-17
  • 2022-01-08
  • 2021-07-25
  • 2021-06-15
  • 2022-03-05
  • 2021-11-02
猜你喜欢
  • 2021-10-03
  • 2021-11-22
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案