The fourth Blue Bridge cup question-Sloppy formula, the fourth Blue Bridge
Enumeration
James is an acute child. When he was in elementary school, he often copied the questions that the teacher wrote on the blackboard wrong.
On one occasion, the instructor gave the Question 36x495 =?
He copied: 396x45 =?
But the results were dramatic. His answer was correct!
Because 36*495 = 396*45 = 17820.
There may be many coincidences like this, such as 27*594 = 297*54.
Assume that a B c d e represents 1 ~ 9 different 5 numbers (note that they are different numbers and do not contain 0 ).
Which of the following formula can be satisfied: AB * cde = adb * ce?
Please take advantage of the computer to find all possibilities and answer the different types of formulas.
The formula that satisfies the multiplication exchange law is counted as different types, so the answer must be an even number.
#include<iostream>using namespace std;int main(){ int a,b,c,d,e,num=0; for(a=1;a<10;a++) { for(b=1;b<10;b++) { if(a==b) continue; for(c=1;c<10;c++) { if(a==c||b==c) continue; for(d=1;d<10;d++) { if(a==d||b==d||c==d) continue; for(e=1;e<10;e++) { if(a==e||b==e||c==e||d==e) continue; if(((a*10+b)*(c*100+d*10+e))==((a*100+d*10+b)*(c*10+e))) num++; } } } } } cout<<num<<endl; return 0;}
Because there are a total of five numbers, it is better to have a five-weight loop, instead of a nine-weight loop.