Implementación de Python de cálculo mágico

Directorio de artículos

problema

4个不同的数字,组成的一个乘法算式,它们的乘积仍然由这4个数字组成。
比如: 210 x 6 = 1260 8 x 473 = 3784 27 x 81 = 2187
都符合要求。
如果满足乘法交换律的算式算作同一种情况,那么,包含上边已列出的3种情况,一共有多少种满足要求的算式。
请填写该数字,通过浏览器提交答案,不要填写多余内容(例如:列出所有算式)。

Idea y código

Los cuatro dígitos de la violencia,
donde p es para eliminar los duplicados

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)

Supongo que te gusta

Origin blog.csdn.net/qq_49821869/article/details/114837852
Recomendado
Clasificación