import Java.util.arraylist;import java.util.List; Public classStrtest { Public Static voidMain (string[] args) {//simulation generates a large integerLong n=Shengcheng (); //split this big integer to see what 's made of it.list<long> list =splitnumber (n); for(intI=0; I<list.size (); i++) {System. out. println (list.Get(i)); } } /** function: Calculates 2 of the whole number of times * Yellow Sea * Time: 2016-01-20 * @param n * @return*/ Private Static LongGetnumberbyid (intN) {return(Long) Math.pow (2, N); } /** Function: Simulation generates an integer that is combined with 2 of the whole number of times * Yellow Sea * Time: 2016-01-20 * @return*/ Private Static LongShengcheng () {LongA=getnumberbyid (1) +getnumberbyid (2) +getnumberbyid (3) +getnumberbyid (5) +getnumberbyid (8) +getnumberbyid ( A) +getnumberbyid ( -); System. out. println (a); returnA; } /** Function: A whole number of 2 is divided into one integer and added together, split into a 2 of the whole number of forms * @param n * @return*/ Private StaticList<long> Splitnumber (LongN) {List<Long> list =NewArraylist<long>(); String s=long.tobinarystring (n); intlen=s.length (); for(intI=0; i<len;i++) {Long cur=long.parselong (S.substring (len-i-1, len-i)); if(cur>0) {List.add (Getnumberbyid (i)); } } returnlist; }}
Java Edition split large integers to 2 powers and algorithms