215 = 32768 并且其各位之和为 is 3 + 2 + 7 + 6 + 8 = 26.
21000 的各位数之和是多少?
public class Test {public static int sum(int[] total){int sum = 0 ;for(int i : total){sum += i;}return sum;}public static void main(String[] args) {int length = 1000;//结果在数组中逆序排序。int[] total = new int[length/3+1];//根据lg(2^1000)=1000*lg2=1000*0.30103=301.03可知结果不会超过334位total[0] = 1;int n = 0; //记录当前有效倍数for(int i = 0 ;i < length; i ++){for(int j = 0 ; j <= n ; j ++){total[j] *= 2;}for(int j = 0 ; j <= n ; j ++){if(total[j] >= 10){total[j] %= 10;total[j+1]++;if(n < length/3){n++; }}}}System.out.println(sum(total));}
}