Despite their size, the sum of the digits in each number is only 1.
Considering natural numbers of the form ‘ab,’ where a, b < 100, what is the maximum digital sum?
Maximum digital sum = 972
Let’s look at the code snippet below. It gives a solution for how to calculate the powerful digital sum of a, b < 100.
a = 100b = 100maxSum = 0for i in range(a):for j in range(b):temp = i**j #i**j = i^jtemp = map(int, str(temp)) #mapping int to string as it is less costly to parse strings than dealing with big integerssumList = list(temp) #making a list of numberstempSum = sum(sumList); #calculating sum of digitsif(tempSum > maxSum):maxSum = tempSum #finding max sumprint "Maximum digital sum = ", maxSum
The nested loop calculates the exponent , where 0<i<100 and 0<j<100. The sum of the digits of the exponent is calculated in line 10 and the maximum digit sum is stored in maxSum
in line 12. This is the powerful digital sum for a<100 and b<100.
Free Resources