A vampire number is a number with an even number of digits, obtained by a pair of multiplied numbers, and each number contains a number that is half the number of digits of the product.
Such as:
1092:12*91
1207:17*71
1250:25*50
1260:21*60
1275:17*75
1278:18*71
1325:25*53
Find out 4-digit numbers of all vampires.
//: Main.javaImportJava.util.ArrayList;/** * Vampire number * *Class Main { Public Static Boolean Vampire(intnum) {String snum = integer.tostring (num);Char[] AC = Snum.tochararray ();//Two number of stitchingArraylist<string> as =NewArraylist<string> (); for(intI=0; i<ac.length; ++i) { for(intj=0; j<ac.length; ++J) {if(j = = i)Continue; String tmp =""+ac[i] + ac[j]; As.add (TMP); } }//Convert numbers int[] ai =New int[As.size ()]; for(intI=0; I<as.size (); ++i) {Ai[i] = integer.valueof (As.get (i)); }//Verify vampire numbers for(intI=0; I<as.size (); ++i) { for(intj=0; J<as.size (); ++J) {if(j = = i)Continue;if(Ai[i] * ai[j] = = num) {System.out.println (num +": "+ Ai[i] +"*"+ ai[j]);return true; } } }return false; } Public Static void Main(string[] args) { for(intI= +; i<10000; ++i) {Vampire (i); } }}/** * output:1092:12*91 1207:17*71 1250:25*50 1260:21*60 1275:17*75 1278:18*71 1325:25*53 ... * *//:~
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java-Vampire numbers