public class Test_吸血鬼数字 {
public static void main(String[] args) { int count = 0;boolean flag = false;
for (int a = 1; a < 10; a++) {
for (int b = 0; b < 10; b++) {
for (int c = 0; c < 10; c++){
for (int d = 0; d < 10; d++) {
int t1 = a * 1000 + b * 100 + c * 10 + d;
for (int A = 1; A < 10; A++) {
for (int B = 0; B < 10; B++) {
int t2 = A * 10 + B;
for (int C = 1; C < 10; C++) {
for (int D = 0; D < 10; D++) {
int t3 = C * 10 + D;
if (((t1 == t2 * t3) && (!(t1 % 10 == 0 && t1 % 100 == 0)))) {
flag = print(a, b, c, d, A, B, C, D);
if (flag) {count++;
System.out.println("第" + count+ "个吸血鬼数字为:" + "\t"+ t1 + "=" + t2 + "*"+ t3); }}}}}}}}}}}
private static boolean print(int a, int b, int c, int d, int A, int B,int C, int D) {
boolean flag = false;
while (!(a <= b && b <= c && c <= d)) {if (a >= b) {int t = a;a = b;b = t;}if (b >= c) {int t = b;b = c;c = t;}if (c >= d) {int t = c;c = d;d = t;}}
while (!(A <= B && B <= C && C <= D)) {
if (A >= B) {int t = A;A = B;B = t;}if (B >= C) {int t = B;B = C;C = t;}if (C >= D) {int t = C;C = D;D = t;}}
if ((a == A) && (b == B) && (c == C) && (d == D)) {flag = true;}return flag;}} |
|