The third-02 sloppy formula

Xiao Ming is impatient. When he was in elementary school, he often copied the questions his teacher wrote 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.

My thoughts: fivefold cycle!
Yes, it can be done, but I didn’t deal with the details well, and ultimately failed

I turned out to be like this (wrong)

public static void main(String[] args) {
    
    
		int count = 0;
		for (int a = 1; a <= 9; a++) {
    
    
			for (int b = 2; b <= 9; b++) {
    
    
				for (int c = 3; c <= 9; c++) {
    
    
					for (int d = 4; d <= 9; d++) {
    
    
						for (int e = 5; e <= 9; e++) {
    
    
							if ((a * b) * (c * d * e) == (a * d * b) * (c * e)) {
    
    
								count++;
							}
						}
					}
				}
			}
		}

	}

Mistakes I made:
1. I didn't understand the values ​​that abcde can take, and I took different values ​​for them in my opinion;
2. No difference, no judgment! ! It should be judged one by one.
3. Did not understand ab * cde = adb * ce. The loops are all single digits, but the numbers in this formula are placed in different positions, and the meanings they represent are also different! It's not just spliced ​​together like this! ! !

correct:

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) {
    
    
										if ((a * 10 + b) * (c * 100 + d * 10 + e) == (a * 100 + d * 10 + b)
												* (c * 10 + e)) {
    
    
											count++;
										}

									}
								}
							}
						}
					}
				}
			}
		}
	}
		System.out.println(count);
}

end.

Guess you like

Origin blog.csdn.net/weixin_44998686/article/details/109003691