问题描述
由 4 个不同的数字,组成的一个乘法算式,它们的乘积仍然由这 4 个数字组成。
比如:
- 210 x 6 = 1260
- 8 x 473 = 3784
- 27 x 81 = 2187
如果满足乘法交换律的算式算作同一种情况,那么,包含上边已列出的 3 种情况,一共有多少种满足要求的算式。
答案提交
请填写该数字,通过浏览器提交答案,不要填写多余内容(例如:列出所有算式)。
答案:12
题解: 人眼去重
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
for (int i = 1023; i < 9876; i ++)
{
int a = i / 1000;
int b = i / 100 % 10;
int c = i / 10 % 10;
int d = i % 10;
if(a == b || a == c || a == d || b == c || b == d || c == d) continue;
int s[4] = {a, b, c, d};
while(next_permutation(s, s + 4))
{
if(s[0] * (s[1]*100 + s[2]*10 + s[3]) == i) printf("%d * %d%d%d\n", s[0], s[1], s[2], s[3]);
if((s[0]*10 + s[1]) * (s[2]*10 + s[3]) == i) printf("%d%d * %d%d\n", s[0], s[1], s[2], s[3]);
}
}
return 0;
}