[Daily Blue Bridge] 3. The real question of the provincial Java group in the first or three years: "Sloppy formula"

Hello, I am the little gray ape, a programmer who can write bugs!

Welcome everyone to pay attention to my column " Daily Blue Bridge ". The main function of this column is to share with you the real questions of the Blue Bridge Cup provincial competitions and finals in recent years, analyze the algorithm ideas, data structures and other content that exist in it, and help you learn To more knowledge and technology!

Title: Sloppy formula

Xiao Ming is impatient, and often copied the teacher's calculations wrong when he was in school.

Once, the teacher asked the question: 36 * 495 =?

He copied it as: 396 * 45 =?

But the result is very dramatic, his answer is actually right!

Because 36*495=396*45=17820

There may be many coincidences like this, for example: 27*594=297*54

Assume 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 expressions 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.

The formulas that satisfy the commutative law of multiplication are counted as different types, so the answer must be an even number

The answer is submitted directly through the browser

Note: Only submit a number that represents the final statistical category, do not submit the answering process or other redundant content

Problem-solving ideas:

This question mainly grasps the key content given in the stem:

Assume 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 expressions can satisfy the form: ab * cde = adb * ce?

So we can find out and judge all possible combinations through enumeration,

At the same time, it is enough to count the number of formulas that meet the requirements.

Answer source code:

package 一三年省赛真题;

public class Year2013_t3 {

	/**
	 * 假设 a b c d e 代表1~9不同的5个数字(注意是各不相同的数字,且不含0)
	能满足形如:ab * cde = adb * ce 这样的算式一共有多少种呢?
	 * */
	public static void main(String[] args) {
		int count = 0;
		for (int a = 1; a < 10; a++) {
			for (int b = 1; b < 10; b++) {
				if (a!=b) {
					for (int c = 1; c < 10; c++) {
						if (c!=a&&c!=b) {
							for (int d = 1; d < 10; d++) {
								if (d!=a&&d!=b&&d!=c) {
									for (int e = 1; e < 10; e++) {
										if (e!=a&&e!=b&&e!=c&&e!=d) {
											int x = (a*10+b)*(c*100+d*10+e);
											int y = (a*100+d*10+b)*(c*10+e);
											if (x==y) {
												count++;
												System.out.printf("(%d*10+%d)*(%d*100+%d*10+%d)==(%d*100+%d*10+%d)*(%d*10+%d)==%d\n",a,b,c,d,e,a,d,b,c,e,x);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		System.out.println(count);

	}

}

 

Sample output:

There are deficiencies or improvements, and I hope my friends will leave a message and learn together!

Interested friends can follow the column!

Little Grey Ape will accompany you to make progress together!

Guess you like

Origin blog.csdn.net/weixin_44985880/article/details/112542327