如何用Python解这道数学题?
a~i对应1~9这九个数的任意数,使ab*c=def=gh*i成立ab*c=def=gh*ia,b,c,d,e,f,g,h,i分别是1,2,3,4,5,6,7,8,9这九...
a~i对应1~9这九个数的任意数,使ab*c=def=gh*i成立
ab*c=def=gh*i
a,b,c,d,e,f,g,h,i分别是1,2,3,4,5,6,7,8,9这九个数 展开
ab*c=def=gh*i
a,b,c,d,e,f,g,h,i分别是1,2,3,4,5,6,7,8,9这九个数 展开
1个回答
展开全部
def perm(str_list, k, m,r):
if k >= m:
r.append(''.join(str_list))
else:
for i in range(k ,m):
str_list[k],str_list[i] = str_list[i],str_list[k]
perm(str_list, k+1,m,r)
str_list[k], str_list[i] = str_list[i], str_list[k]
r = []
perm(list('123456789'), 0,9,r)
for item in r:
a,b,c,d,e,f,g,h,i = int(item[0]),int(item[1]),int(item[2]),int(item[3]),int(item[4]),int(item[5]),int(item[6]),int(item[7]),int(item[8])
if ((10*a+b)*c == 100*d+10*e+f) and ((10*g+h)*i == 100*d+10*e+f):
print a,b,c,d,e,f,g,h,i
if k >= m:
r.append(''.join(str_list))
else:
for i in range(k ,m):
str_list[k],str_list[i] = str_list[i],str_list[k]
perm(str_list, k+1,m,r)
str_list[k], str_list[i] = str_list[i], str_list[k]
r = []
perm(list('123456789'), 0,9,r)
for item in r:
a,b,c,d,e,f,g,h,i = int(item[0]),int(item[1]),int(item[2]),int(item[3]),int(item[4]),int(item[5]),int(item[6]),int(item[7]),int(item[8])
if ((10*a+b)*c == 100*d+10*e+f) and ((10*g+h)*i == 100*d+10*e+f):
print a,b,c,d,e,f,g,h,i
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询