吸血鬼数字介绍
吸血鬼数字是指位数为偶数的数字,可以由一对数字相乘而得到,而这对数字各包含乘积的一半位数的数字,其中从最初的数字中选取的数字可以任意排序。以两个0结尾的数字是不允许的,例如,下列数字都是“吸血鬼”数字:
1260 = 21 * 60 1827 = 21 * 87 2187 = 27 * 81查找四位的吸血鬼数字算法如下:
package com.test.lhg;
import java.util.Arrays;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
int n = findXuXueGuiShu();
System.out.println("共找到"+n+"组吸血鬼数");
}
/**
* 查找4位的吸血鬼数
* @return
*/
public static int findXuXueGuiShu() {
int sum = 0;
for (int i = 10; i < 100; i++) {
for (int j = i+1; j < 100; j++) {
int product = i * j;
if (product<1000 || product>10000 || product %100==0) {
continue;
}
String strProduct = ""+product;
String gene = ""+i+j;
char[] arrProduct = strProduct.toCharArray();
char[] arrgene = gene.toCharArray();
Arrays.sort(arrProduct);
Arrays.sort(arrgene);
if (Arrays.equals(arrProduct, arrgene)) {
sum ++;
System.out.println("第"+sum+"组:"+i+"*"+j+"="+product);
}
}
}
return sum;
}
}/*
第1组:15*93=1395
第2组:21*60=1260
第3组:21*87=1827
第4组:27*81=2187
第5组:30*51=1530
第6组:35*41=1435
第7组:80*86=6880
共找到7组吸血鬼数
* /
230

被折叠的 条评论
为什么被折叠?



