马虎的算式
2017-03-13 20:30
120 查看
假设
a b c d e 代表1~9不同的5个数字(注意是各不相同的数字,且不含0),能满足形如:
ab * cde = adb* ce 这样的算式一共有多少种呢?
int a,b,c,d,e; int count=0; for(a=1;a<=9;a++) for(b=1;b<=9;b++) for(c=1;c<=9;c++) for(d=1;d<=9;d++) for(e=1;e<=9;e++){ if (a != b && a != c && a != d && a != e && b != c&& b != d && b != e && c != d && c != e&& d != e) if((a*10+b)*(c*100+d*10+e)==(a*100+d*10+b)*(c*10+e)) count++; }
主要注意的是五个不同的数,然后再进行就可以了
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/tongue.gif)