标题:神奇算式
由4个不同的数字,组成的一个乘法算式,它们的乘积仍然由这4个数字组成。
比如:
210 x 6 = 1260
8 x 473 = 3784
27 x 81 = 2187
都符合要求。
如果满足乘法交换律的算式算作同一种情况,那么,包含上边已列出的3种情况,一共有多少种满足要求的算式。
请填写该数字,通过浏览器提交答案,不要填写多余内容(例如:列出所有算式)。
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int m[5];
bool find(int x){
int i=0;
while(x){
m[i++]=x%10;
x/=10;
}
if(i==4)return true;
else return false;
}
int main()
{
int B[5],count=0,ct=0;
for(int a=0;a<=9;a++)
for(int b=0;b<=9;b++){
if(a!=b){
for(int c=0;c<=9;c++){
if(a!=c&&b!=c){
for(int d=0;d<=9;d++){
if(a!=d&&d!=b&&c!=d){
int A=a*100+b*10+c;
int C=a*10+b;
int D=c*10+d;
B[0]=a;B[1]=b;B[2]=c;B[3]=d;
sort(B,B+4);
if(find(A*d)){
sort(m,m+4);
if(m[0]==B[0]&&m[1]==B[1]&&m[2]==B[2]&&m[3]==B[3]){
printf("%d * %d = %d\n",A,d,A*d);
count++;
}
}
if(find(C*D)){
sort(m,m+4);
if(m[0]==B[0]&&m[1]==B[1]&&m[2]==B[2]&&m[3]==B[3]){
printf("%d * %d = %d\n",C,D,C*D);
ct++;
}
}
}
}
}
}
}
}
printf("%d %d\n",count,ct);
return 0;
}
15 * 93 = 1395 ///
201 * 6 = 1206
210 * 6 = 1260
21 * 60 = 1260///
21 * 87 = 1827///
27 * 81 = 2187///
30 * 51 = 1530///
351 * 9 = 3159
35 * 41 = 1435
41 * 35 = 1435
473 * 8 = 3784
501 * 3 = 1503
510 * 3 = 1530
51 * 30 = 1530
60 * 21 = 1260
81 * 27 = 2187
87 * 21 = 1827
93 * 15 = 1395
6 12
里面有重复的算式,经过比较可得出一共12个