问题
由4个不同的数字,组成的一个乘法算式,它们的乘积仍然由这4个数字组成。
比如: 210 x 6 = 1260 8 x 473 = 3784 27 x 81 = 2187
都符合要求。
如果满足乘法交换律的算式算作同一种情况,那么,包含上边已列出的3种情况,一共有多少种满足要求的算式。
请填写该数字,通过浏览器提交答案,不要填写多余内容(例如:列出所有算式)。
思路及代码
暴力所有四位数
这里的p是为了去除重复的情况
num = 0
p = 0
for i in range(1000, 10000):
a = str(i)
if len(set(a)) == 4:
for x in a:
for y in a:
for m in a:
for n in a:
if x != y and x != m and x != n and y != m and y != n and m != n:
if int(str(x) + str(y)) * int(str(m) + str(n)) == i and int(str(x) + str(y)) != p:
p = int(str(m) + str(n))
num += 1
elif int(str(x) + str(y) + str(m)) * int(str(n)) == i:
num += 1
print(num)