Project Euler: Problem 56

By | 1. September 2013

A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.
Considering natural numbers of the form, ab, where a, b

int largest = 0;
for (long a = 1; a < 100; a++) {
	for (int b = 1; b < 100; b++) {
		BigInteger number = BigInteger.valueOf(a);
		number = number.pow(b);
		String tempnumber = number.toString();
		int temp = 0;
		for (int i = 0; i < tempnumber.length(); i++) {
			temp += tempnumber.charAt(i)-48;
		}
		if (temp > largest) {
			largest = temp;
		}
	} 
}
System.out.println(largest);

Lösung: 972

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert