The seventh question of JAVA Blue Bridge Cup 2014

Java sloppy arithmetic

Xiao Ming is an impatient person. When he was in elementary school, he often copied the questions written by the teacher on the blackboard by mistake.

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

He copied it as: 396 x 45 = ?

But the result was dramatic, his answer turned out to be right! !

because 36 * 495 = 396 * 45 = 17820

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

Suppose abcde represents 5 different numbers from 1 to 9 (note that they are different numbers and do not contain 0)

How many formulas can there be in the form: ab * cde = adb * ce?

public static void main(String[] args) {
    
    
		// TODO Auto-generated method stub
		int cnt = 0;
		for (int a = 1; a <= 9; a++) {
    
    
			for (int b = 1; b <= 9; b++) {
    
    
				if (b != a)
					for (int c = 1; c <= 9; c++) {
    
    
						if (c != b && c != a)
							for (int d = 1; d <= 9; d++) {
    
    
								if (d != c && d != b && d != a)
									for (int e = 1; e <= 9; 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))
												cnt++;
									}
							}
					}
			}
		}
		System.out.println(cnt);
	}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325073279&siteId=291194637
Recommended