题目大意如下:
找出满足 a = x^3 + y^3 + z^3 和 a = m^3 + n^3 + o^3 的 a 及其 x,y,z,m,n,o 的正整数值,其中 1 <= a <= 1000000。
试了用 Python 写了,代码如下:
flag={}
for x in range(1,100):
for y in range(x+1,100):
for z in range(y+1,100):
a=x*x*x+y*y*y+z*z*z
xyz="(%2d,%2d,%2d)" % (x,y,z)
if a<=1000000:
if a in flag:
mno=flag.get(a)
flag[a]=xyz + " vs " + mno
else:
flag[a]=xyz
#for k,v in flag.iteritems():
# if v.find("vs") != -1:
# print k, v
for i in range(1,1000000):
if i in flag:
xyzmno = flag.get(i)
if xyzmno.find("vs") != -1:
print "%7d %s" % (i, xyzmno)
|
阅读(1470) | 评论(0) | 转发(0) |