Sloppy calculations ~ 1/11

As the title

Xiao Ming is impatient. When he was in elementary school, he often copied the questions his teacher had written on the blackboard wrong.
Once, the teacher asked the question: 36 x 495 =?
He copied it: 396 x 45 =?
But the result was dramatic, and his answer turned out to be correct! !
Because 36 * 495 = 396 * 45 = 17820
There may be many coincidences like this, for example: 27 * 594 = 297 * 54

Assuming that abcde represents 5 different numbers from 1 to 9 (note that they are different numbers, and do not contain 0),
how many kinds of calculations can satisfy the form: ab * cde = adb * ce?
Please use the advantages of computers to find all the possibilities and answer the types and numbers of different calculations.
Formulas that satisfy the commutative law of multiplication are counted as different types, so the answer must be an even number.

First extract the message given by the title:
1.5 different numbers between 1-9. abcde
2.ab cde=adb ce. (It can be seen here that d is a number stuffed in the middle)
3. The answer is an even number

Exhaustive approach

code show as below:

#include <stdio.h>
int main()
{
    
    
	int a,b,c,d,e;//先定义五个数,这五个数都是1~9的
	int i,j,k;//备用
	//这个题可以用穷举法来计算
	k = 0;
	for(a=1;a<=9;a++)//a是属于1~9的数
	{
    
    
		for(b=1;b<=9;b++)
		{
    
    
			if(a!=b)//a不等于b才有接下来的故事
			{
    
    
				for(c=1;c<=9;c++)
				{
    
    
					if(c!=a&&c!=b)//c及既不等于a,也不等于b
					{
    
    
						for(d=1;d<=9;d++)
						{
    
    
							if(d!=a&&d!=b&&d!=c)//以下与上面雷同(doge 
							{
    
    
								for(e=1;e<=9;e++)
								{
    
    
									if(e!=a&&e!=b&&e!=c&&e!=d)
									{
    
    
										i = (a*10+b)*(c*100+d*10+e);//这就是题目上的关键点了,
										j = (a*100+d*10+b)*(c*10+e);//可以看做是d就是在中间变动的个数字
										if(i==j)//如果i==j的话,那么统计的数字就会多一个 
										{
    
    
											k++;
										}
									}
								}
							}
						}
					 } 
				}
			 } 
		}
	 }
	 printf("%d",k);//最后把统计的数字返回,打出就可以了 
	
}

The running screenshot is as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/FG_future/article/details/112466050
Recommended