How to calculate the powerful digital sum
Problem statement
- A googol () is a massive number, i.e., one followed by one hundred zeros.
- () is almost unimaginably large, i.e., 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 < 100, what is the maximum digital sum?
Expected output
Maximum digital sum = 972
Solution
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
Explanation
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
Copyright ©2026 Educative, Inc. All rights reserved