Problem 16 of 2的1000次方

215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 21000?

http://projecteuler.net/problem=16

import java.math.BigInteger;

public class SumDigitsTwo {
	public static void main(String args[]) {
		int sum=0;
		String str=pow("2", 1000);
		for(int i=0;i<str.length();i++){
			sum+=Integer.parseInt(str.substring(i,i+1));
		}
		System.out.print(sum);
	}
	public static String pow(String a,int b){
		BigInteger bi=new BigInteger(a).pow(1000);
		return bi.toString();
	}
}

Answer:
1366

你可能感兴趣的:(String,BI,Class,import)